| ... | @@ -269,7 +269,7 @@ pub const InstMap = struct { | ... | @@ -269,7 +269,7 @@ pub const InstMap = struct { |
| 269 | while (true) { | 269 | while (true) { |
| 270 | const extra_capacity = better_capacity / 2 + 16; | 270 | const extra_capacity = better_capacity / 2 + 16; |
| 271 | better_capacity += extra_capacity; | 271 | better_capacity += extra_capacity; |
| 272 | better_start -|= @as(Zir.Inst.Index, @intCast(extra_capacity / 2)); | 272 | better_start -|= @intCast(extra_capacity / 2); |
| 273 | if (better_start <= start and end < better_capacity + better_start) | 273 | if (better_start <= start and end < better_capacity + better_start) |
| 274 | break; | 274 | break; |
| 275 | } | 275 | } |
| ... | @@ -282,7 +282,7 @@ pub const InstMap = struct { | ... | @@ -282,7 +282,7 @@ pub const InstMap = struct { |
| 282 | | 282 | |
| 283 | allocator.free(map.items); | 283 | allocator.free(map.items); |
| 284 | map.items = new_items; | 284 | map.items = new_items; |
| 285 | map.start = @as(Zir.Inst.Index, @intCast(better_start)); | 285 | map.start = @intCast(better_start); |
| 286 | } | 286 | } |
| 287 | }; | 287 | }; |
| 288 | | 288 | |
| ... | @@ -405,7 +405,9 @@ pub const Block = struct { | ... | @@ -405,7 +405,9 @@ pub const Block = struct { |
| 405 | /// It is shared among all the blocks in an inline or comptime called | 405 | /// It is shared among all the blocks in an inline or comptime called |
| 406 | /// function. | 406 | /// function. |
| 407 | pub const Inlining = struct { | 407 | pub const Inlining = struct { |
| 408 | /// Might be `none`. | 408 | call_block: *Block, |
| | 409 | call_src: LazySrcLoc, |
| | 410 | has_comptime_args: bool, |
| 409 | func: InternPool.Index, | 411 | func: InternPool.Index, |
| 410 | comptime_result: Air.Inst.Ref, | 412 | comptime_result: Air.Inst.Ref, |
| 411 | merges: Merges, | 413 | merges: Merges, |
| ... | @@ -681,7 +683,7 @@ pub const Block = struct { | ... | @@ -681,7 +683,7 @@ pub const Block = struct { |
| 681 | const sema = block.sema; | 683 | const sema = block.sema; |
| 682 | const ty_ref = Air.internedToRef(aggregate_ty.toIntern()); | 684 | const ty_ref = Air.internedToRef(aggregate_ty.toIntern()); |
| 683 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements.len); | 685 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements.len); |
| 684 | const extra_index = @as(u32, @intCast(sema.air_extra.items.len)); | 686 | const extra_index: u32 = @intCast(sema.air_extra.items.len); |
| 685 | sema.appendRefsAssumeCapacity(elements); | 687 | sema.appendRefsAssumeCapacity(elements); |
| 686 | | 688 | |
| 687 | return block.addInst(.{ | 689 | return block.addInst(.{ |
| ... | @@ -722,7 +724,7 @@ pub const Block = struct { | ... | @@ -722,7 +724,7 @@ pub const Block = struct { |
| 722 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); | 724 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 723 | try block.instructions.ensureUnusedCapacity(gpa, 1); | 725 | try block.instructions.ensureUnusedCapacity(gpa, 1); |
| 724 | | 726 | |
| 725 | const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 727 | const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 726 | sema.air_instructions.appendAssumeCapacity(inst); | 728 | sema.air_instructions.appendAssumeCapacity(inst); |
| 727 | block.instructions.appendAssumeCapacity(result_index); | 729 | block.instructions.appendAssumeCapacity(result_index); |
| 728 | return result_index; | 730 | return result_index; |
| ... | @@ -740,7 +742,7 @@ pub const Block = struct { | ... | @@ -740,7 +742,7 @@ pub const Block = struct { |
| 740 | | 742 | |
| 741 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); | 743 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 742 | | 744 | |
| 743 | const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 745 | const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 744 | sema.air_instructions.appendAssumeCapacity(inst); | 746 | sema.air_instructions.appendAssumeCapacity(inst); |
| 745 | | 747 | |
| 746 | try block.instructions.insert(gpa, index, result_index); | 748 | try block.instructions.insert(gpa, index, result_index); |
| ... | @@ -818,6 +820,11 @@ const InferredAlloc = struct { | ... | @@ -818,6 +820,11 @@ const InferredAlloc = struct { |
| 818 | }) = .{}, | 820 | }) = .{}, |
| 819 | }; | 821 | }; |
| 820 | | 822 | |
| | 823 | const NeededComptimeReason = struct { |
| | 824 | needed_comptime_reason: []const u8, |
| | 825 | block_comptime_reason: ?*const Block.ComptimeReason = null, |
| | 826 | }; |
| | 827 | |
| 821 | pub fn deinit(sema: *Sema) void { | 828 | pub fn deinit(sema: *Sema) void { |
| 822 | const gpa = sema.gpa; | 829 | const gpa = sema.gpa; |
| 823 | sema.air_instructions.deinit(gpa); | 830 | sema.air_instructions.deinit(gpa); |
| ... | @@ -849,7 +856,7 @@ fn resolveBody( | ... | @@ -849,7 +856,7 @@ fn resolveBody( |
| 849 | body_inst: Zir.Inst.Index, | 856 | body_inst: Zir.Inst.Index, |
| 850 | ) CompileError!Air.Inst.Ref { | 857 | ) CompileError!Air.Inst.Ref { |
| 851 | const break_data = (try sema.analyzeBodyBreak(block, body)) orelse | 858 | const break_data = (try sema.analyzeBodyBreak(block, body)) orelse |
| 852 | return Air.Inst.Ref.unreachable_value; | 859 | return .unreachable_value; |
| 853 | // For comptime control flow, we need to detect when `analyzeBody` reports | 860 | // For comptime control flow, we need to detect when `analyzeBody` reports |
| 854 | // that we need to break from an outer block. In such case we | 861 | // that we need to break from an outer block. In such case we |
| 855 | // use Zig's error mechanism to send control flow up the stack until | 862 | // use Zig's error mechanism to send control flow up the stack until |
| ... | @@ -1455,7 +1462,7 @@ fn analyzeBodyInner( | ... | @@ -1455,7 +1462,7 @@ fn analyzeBodyInner( |
| 1455 | try sema.errNote(block, runtime_src, msg, "runtime control flow here", .{}); | 1462 | try sema.errNote(block, runtime_src, msg, "runtime control flow here", .{}); |
| 1456 | break :msg msg; | 1463 | break :msg msg; |
| 1457 | }; | 1464 | }; |
| 1458 | return sema.failWithOwnedErrorMsg(msg); | 1465 | return sema.failWithOwnedErrorMsg(block, msg); |
| 1459 | } | 1466 | } |
| 1460 | } | 1467 | } |
| 1461 | i += 1; | 1468 | i += 1; |
| ... | @@ -1654,10 +1661,10 @@ fn analyzeBodyInner( | ... | @@ -1654,10 +1661,10 @@ fn analyzeBodyInner( |
| 1654 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1661 | 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]; | 1662 | 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]; | 1663 | 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| { | 1664 | 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); | 1665 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1659 | return err; | 1666 | .block_comptime_reason = block.comptime_reason, |
| 1660 | }; | 1667 | }); |
| 1661 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1668 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1662 | | 1669 | |
| 1663 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); | 1670 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| ... | @@ -1675,10 +1682,10 @@ fn analyzeBodyInner( | ... | @@ -1675,10 +1682,10 @@ fn analyzeBodyInner( |
| 1675 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1682 | 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]; | 1683 | 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]; | 1684 | 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| { | 1685 | 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); | 1686 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", |
| 1680 | return err; | 1687 | .block_comptime_reason = block.comptime_reason, |
| 1681 | }; | 1688 | }); |
| 1682 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1689 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1683 | | 1690 | |
| 1684 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); | 1691 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| ... | @@ -1708,10 +1715,10 @@ fn analyzeBodyInner( | ... | @@ -1708,10 +1715,10 @@ fn analyzeBodyInner( |
| 1708 | } | 1715 | } |
| 1709 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1716 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1710 | assert(is_non_err != .none); | 1717 | 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| { | 1718 | 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); | 1719 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1713 | return err; | 1720 | .block_comptime_reason = block.comptime_reason, |
| 1714 | }; | 1721 | }); |
| 1715 | if (is_non_err_val.toBool()) { | 1722 | if (is_non_err_val.toBool()) { |
| 1716 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); | 1723 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); |
| 1717 | } | 1724 | } |
| ... | @@ -1734,10 +1741,10 @@ fn analyzeBodyInner( | ... | @@ -1734,10 +1741,10 @@ fn analyzeBodyInner( |
| 1734 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); | 1741 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1735 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1742 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1736 | assert(is_non_err != .none); | 1743 | 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| { | 1744 | 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); | 1745 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1739 | return err; | 1746 | .block_comptime_reason = block.comptime_reason, |
| 1740 | }; | 1747 | }); |
| 1741 | if (is_non_err_val.toBool()) { | 1748 | if (is_non_err_val.toBool()) { |
| 1742 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 1749 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 1743 | } | 1750 | } |
| ... | @@ -1757,7 +1764,7 @@ fn analyzeBodyInner( | ... | @@ -1757,7 +1764,7 @@ fn analyzeBodyInner( |
| 1757 | else => |e| return e, | 1764 | else => |e| return e, |
| 1758 | }; | 1765 | }; |
| 1759 | if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn; | 1766 | if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn; |
| 1760 | break :blk Air.Inst.Ref.void_value; | 1767 | break :blk .void_value; |
| 1761 | }, | 1768 | }, |
| 1762 | .defer_err_code => blk: { | 1769 | .defer_err_code => blk: { |
| 1763 | const inst_data = sema.code.instructions.items(.data)[inst].defer_err_code; | 1770 | const inst_data = sema.code.instructions.items(.data)[inst].defer_err_code; |
| ... | @@ -1770,7 +1777,7 @@ fn analyzeBodyInner( | ... | @@ -1770,7 +1777,7 @@ fn analyzeBodyInner( |
| 1770 | else => |e| return e, | 1777 | else => |e| return e, |
| 1771 | }; | 1778 | }; |
| 1772 | if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn; | 1779 | if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn; |
| 1773 | break :blk Air.Inst.Ref.void_value; | 1780 | break :blk .void_value; |
| 1774 | }, | 1781 | }, |
| 1775 | }; | 1782 | }; |
| 1776 | if (sema.isNoReturn(air_inst)) { | 1783 | if (sema.isNoReturn(air_inst)) { |
| ... | @@ -1819,7 +1826,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { | ... | @@ -1819,7 +1826,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 1819 | const i = @intFromEnum(zir_ref); | 1826 | const i = @intFromEnum(zir_ref); |
| 1820 | // First section of indexes correspond to a set number of constant values. | 1827 | // First section of indexes correspond to a set number of constant values. |
| 1821 | // We intentionally map the same indexes to the same values between ZIR and AIR. | 1828 | // We intentionally map the same indexes to the same values between ZIR and AIR. |
| 1822 | if (i < InternPool.static_len) return @as(Air.Inst.Ref, @enumFromInt(i)); | 1829 | if (i < InternPool.static_len) return @enumFromInt(i); |
| 1823 | // The last section of indexes refers to the map of ZIR => AIR. | 1830 | // The last section of indexes refers to the map of ZIR => AIR. |
| 1824 | const inst = sema.inst_map.get(i - InternPool.static_len).?; | 1831 | const inst = sema.inst_map.get(i - InternPool.static_len).?; |
| 1825 | if (inst == .generic_poison) return error.GenericPoison; | 1832 | if (inst == .generic_poison) return error.GenericPoison; |
| ... | @@ -1831,7 +1838,7 @@ fn resolveConstBool( | ... | @@ -1831,7 +1838,7 @@ fn resolveConstBool( |
| 1831 | block: *Block, | 1838 | block: *Block, |
| 1832 | src: LazySrcLoc, | 1839 | src: LazySrcLoc, |
| 1833 | zir_ref: Zir.Inst.Ref, | 1840 | zir_ref: Zir.Inst.Ref, |
| 1834 | reason: []const u8, | 1841 | reason: NeededComptimeReason, |
| 1835 | ) !bool { | 1842 | ) !bool { |
| 1836 | const air_inst = try sema.resolveInst(zir_ref); | 1843 | const air_inst = try sema.resolveInst(zir_ref); |
| 1837 | const wanted_type = Type.bool; | 1844 | const wanted_type = Type.bool; |
| ... | @@ -1845,7 +1852,7 @@ pub fn resolveConstString( | ... | @@ -1845,7 +1852,7 @@ pub fn resolveConstString( |
| 1845 | block: *Block, | 1852 | block: *Block, |
| 1846 | src: LazySrcLoc, | 1853 | src: LazySrcLoc, |
| 1847 | zir_ref: Zir.Inst.Ref, | 1854 | zir_ref: Zir.Inst.Ref, |
| 1848 | reason: []const u8, | 1855 | reason: NeededComptimeReason, |
| 1849 | ) ![]u8 { | 1856 | ) ![]u8 { |
| 1850 | const air_inst = try sema.resolveInst(zir_ref); | 1857 | const air_inst = try sema.resolveInst(zir_ref); |
| 1851 | const wanted_type = Type.slice_const_u8; | 1858 | const wanted_type = Type.slice_const_u8; |
| ... | @@ -1859,7 +1866,7 @@ pub fn resolveConstStringIntern( | ... | @@ -1859,7 +1866,7 @@ pub fn resolveConstStringIntern( |
| 1859 | block: *Block, | 1866 | block: *Block, |
| 1860 | src: LazySrcLoc, | 1867 | src: LazySrcLoc, |
| 1861 | zir_ref: Zir.Inst.Ref, | 1868 | zir_ref: Zir.Inst.Ref, |
| 1862 | reason: []const u8, | 1869 | reason: NeededComptimeReason, |
| 1863 | ) !InternPool.NullTerminatedString { | 1870 | ) !InternPool.NullTerminatedString { |
| 1864 | const air_inst = try sema.resolveInst(zir_ref); | 1871 | const air_inst = try sema.resolveInst(zir_ref); |
| 1865 | const wanted_type = Type.slice_const_u8; | 1872 | const wanted_type = Type.slice_const_u8; |
| ... | @@ -1905,7 +1912,7 @@ fn resolveDestType( | ... | @@ -1905,7 +1912,7 @@ fn resolveDestType( |
| 1905 | try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{}); | 1912 | try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{}); |
| 1906 | break :msg msg; | 1913 | break :msg msg; |
| 1907 | }; | 1914 | }; |
| 1908 | return sema.failWithOwnedErrorMsg(msg); | 1915 | return sema.failWithOwnedErrorMsg(block, msg); |
| 1909 | }, | 1916 | }, |
| 1910 | else => |e| return e, | 1917 | else => |e| return e, |
| 1911 | }; | 1918 | }; |
| ... | @@ -1931,7 +1938,9 @@ fn analyzeAsType( | ... | @@ -1931,7 +1938,9 @@ fn analyzeAsType( |
| 1931 | ) !Type { | 1938 | ) !Type { |
| 1932 | const wanted_type = Type.type; | 1939 | const wanted_type = Type.type; |
| 1933 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 1940 | 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"); | 1941 | const val = try sema.resolveConstValue(block, src, coerced_inst, .{ |
| | 1942 | .needed_comptime_reason = "types must be comptime-known", |
| | 1943 | }); |
| 1935 | return val.toType(); | 1944 | return val.toType(); |
| 1936 | } | 1945 | } |
| 1937 | | 1946 | |
| ... | @@ -1984,7 +1993,7 @@ fn resolveValue( | ... | @@ -1984,7 +1993,7 @@ fn resolveValue( |
| 1984 | block: *Block, | 1993 | block: *Block, |
| 1985 | src: LazySrcLoc, | 1994 | src: LazySrcLoc, |
| 1986 | air_ref: Air.Inst.Ref, | 1995 | air_ref: Air.Inst.Ref, |
| 1987 | reason: []const u8, | 1996 | reason: NeededComptimeReason, |
| 1988 | ) CompileError!Value { | 1997 | ) CompileError!Value { |
| 1989 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { | 1998 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 1990 | if (val.isGenericPoison()) return error.GenericPoison; | 1999 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2000,7 +2009,7 @@ fn resolveConstMaybeUndefVal( | ... | @@ -2000,7 +2009,7 @@ fn resolveConstMaybeUndefVal( |
| 2000 | block: *Block, | 2009 | block: *Block, |
| 2001 | src: LazySrcLoc, | 2010 | src: LazySrcLoc, |
| 2002 | inst: Air.Inst.Ref, | 2011 | inst: Air.Inst.Ref, |
| 2003 | reason: []const u8, | 2012 | reason: NeededComptimeReason, |
| 2004 | ) CompileError!Value { | 2013 | ) CompileError!Value { |
| 2005 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { | 2014 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { |
| 2006 | if (val.isGenericPoison()) return error.GenericPoison; | 2015 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2018,7 +2027,7 @@ fn resolveConstValue( | ... | @@ -2018,7 +2027,7 @@ fn resolveConstValue( |
| 2018 | block: *Block, | 2027 | block: *Block, |
| 2019 | src: LazySrcLoc, | 2028 | src: LazySrcLoc, |
| 2020 | air_ref: Air.Inst.Ref, | 2029 | air_ref: Air.Inst.Ref, |
| 2021 | reason: []const u8, | 2030 | reason: NeededComptimeReason, |
| 2022 | ) CompileError!Value { | 2031 | ) CompileError!Value { |
| 2023 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { | 2032 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { |
| 2024 | if (val.isGenericPoison()) return error.GenericPoison; | 2033 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | @@ -2037,7 +2046,7 @@ fn resolveConstLazyValue( | ... | @@ -2037,7 +2046,7 @@ fn resolveConstLazyValue( |
| 2037 | block: *Block, | 2046 | block: *Block, |
| 2038 | src: LazySrcLoc, | 2047 | src: LazySrcLoc, |
| 2039 | air_ref: Air.Inst.Ref, | 2048 | air_ref: Air.Inst.Ref, |
| 2040 | reason: []const u8, | 2049 | reason: NeededComptimeReason, |
| 2041 | ) CompileError!Value { | 2050 | ) CompileError!Value { |
| 2042 | return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason)); | 2051 | return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason)); |
| 2043 | } | 2052 | } |
| ... | @@ -2140,15 +2149,18 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | ... | @@ -2140,15 +2149,18 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 2140 | return val; | 2149 | return val; |
| 2141 | } | 2150 | } |
| 2142 | | 2151 | |
| 2143 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: []const u8) CompileError { | 2152 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2144 | const msg = msg: { | 2153 | const msg = msg: { |
| 2145 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); | 2154 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); |
| 2146 | errdefer msg.destroy(sema.gpa); | 2155 | errdefer msg.destroy(sema.gpa); |
| | 2156 | try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason}); |
| 2147 | | 2157 | |
| 2148 | try sema.errNote(block, src, msg, "{s}", .{reason}); | 2158 | if (reason.block_comptime_reason) |block_comptime_reason| { |
| | 2159 | try block_comptime_reason.explain(sema, msg); |
| | 2160 | } |
| 2149 | break :msg msg; | 2161 | break :msg msg; |
| 2150 | }; | 2162 | }; |
| 2151 | return sema.failWithOwnedErrorMsg(msg); | 2163 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2152 | } | 2164 | } |
| 2153 | | 2165 | |
| 2154 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 2166 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| ... | @@ -2181,7 +2193,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty | ... | @@ -2181,7 +2193,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty |
| 2181 | } | 2193 | } |
| 2182 | break :msg msg; | 2194 | break :msg msg; |
| 2183 | }; | 2195 | }; |
| 2184 | return sema.failWithOwnedErrorMsg(msg); | 2196 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2185 | } | 2197 | } |
| 2186 | | 2198 | |
| 2187 | fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { | 2199 | fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| ... | @@ -2213,7 +2225,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: | ... | @@ -2213,7 +2225,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2213 | try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index}); | 2225 | try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index}); |
| 2214 | break :msg msg; | 2226 | break :msg msg; |
| 2215 | }; | 2227 | }; |
| 2216 | return sema.failWithOwnedErrorMsg(msg); | 2228 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2217 | } | 2229 | } |
| 2218 | return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{ | 2230 | return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{ |
| 2219 | int_ty.fmt(sema.mod), val.fmtValue(int_ty, sema.mod), | 2231 | int_ty.fmt(sema.mod), val.fmtValue(int_ty, sema.mod), |
| ... | @@ -2234,7 +2246,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS | ... | @@ -2234,7 +2246,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS |
| 2234 | try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{}); | 2246 | try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{}); |
| 2235 | break :msg msg; | 2247 | break :msg msg; |
| 2236 | }; | 2248 | }; |
| 2237 | return sema.failWithOwnedErrorMsg(msg); | 2249 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2238 | } | 2250 | } |
| 2239 | | 2251 | |
| 2240 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 2252 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| ... | @@ -2243,7 +2255,7 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError | ... | @@ -2243,7 +2255,7 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError |
| 2243 | errdefer msg.destroy(sema.gpa); | 2255 | errdefer msg.destroy(sema.gpa); |
| 2244 | break :msg msg; | 2256 | break :msg msg; |
| 2245 | }; | 2257 | }; |
| 2246 | return sema.failWithOwnedErrorMsg(msg); | 2258 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2247 | } | 2259 | } |
| 2248 | | 2260 | |
| 2249 | fn failWithInvalidFieldAccess( | 2261 | fn failWithInvalidFieldAccess( |
| ... | @@ -2265,7 +2277,7 @@ fn failWithInvalidFieldAccess( | ... | @@ -2265,7 +2277,7 @@ fn failWithInvalidFieldAccess( |
| 2265 | try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{}); | 2277 | try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 2266 | break :msg msg; | 2278 | break :msg msg; |
| 2267 | }; | 2279 | }; |
| 2268 | return sema.failWithOwnedErrorMsg(msg); | 2280 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2269 | } else if (inner_ty.zigTypeTag(mod) == .ErrorUnion) err: { | 2281 | } else if (inner_ty.zigTypeTag(mod) == .ErrorUnion) err: { |
| 2270 | const child_ty = inner_ty.errorUnionPayload(mod); | 2282 | const child_ty = inner_ty.errorUnionPayload(mod); |
| 2271 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; | 2283 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; |
| ... | @@ -2275,7 +2287,7 @@ fn failWithInvalidFieldAccess( | ... | @@ -2275,7 +2287,7 @@ fn failWithInvalidFieldAccess( |
| 2275 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 2287 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2276 | break :msg msg; | 2288 | break :msg msg; |
| 2277 | }; | 2289 | }; |
| 2278 | return sema.failWithOwnedErrorMsg(msg); | 2290 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2279 | } | 2291 | } |
| 2280 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 2292 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2281 | } | 2293 | } |
| ... | @@ -2376,78 +2388,77 @@ pub fn fail( | ... | @@ -2376,78 +2388,77 @@ pub fn fail( |
| 2376 | args: anytype, | 2388 | args: anytype, |
| 2377 | ) CompileError { | 2389 | ) CompileError { |
| 2378 | const err_msg = try sema.errMsg(block, src, format, args); | 2390 | const err_msg = try sema.errMsg(block, src, format, args); |
| 2379 | return sema.failWithOwnedErrorMsg(err_msg); | 2391 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| 2380 | } | 2392 | } |
| 2381 | | 2393 | |
| 2382 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | 2394 | fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg) CompileError { |
| 2383 | @setCold(true); | 2395 | @setCold(true); |
| 2384 | const gpa = sema.gpa; | 2396 | const gpa = sema.gpa; |
| 2385 | const mod = sema.mod; | 2397 | const mod = sema.mod; |
| 2386 | | 2398 | |
| 2387 | if (crash_report.is_enabled and mod.comp.debug_compile_errors) { | | |
| 2388 | if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; | | |
| 2389 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; | | |
| 2390 | wip_errors.init(gpa) catch unreachable; | | |
| 2391 | Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable; | | |
| 2392 | std.debug.print("compile error during Sema:\n", .{}); | | |
| 2393 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; | | |
| 2394 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); | | |
| 2395 | crash_report.compilerPanic("unexpected compile error occurred", null, null); | | |
| 2396 | } | | |
| 2397 | | | |
| 2398 | ref: { | 2399 | ref: { |
| 2399 | errdefer err_msg.destroy(gpa); | 2400 | errdefer err_msg.destroy(gpa); |
| 2400 | if (err_msg.src_loc.lazy == .unneeded) { | 2401 | if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation; |
| 2401 | return error.NeededSourceLocation; | 2402 | |
| | 2403 | if (crash_report.is_enabled and mod.comp.debug_compile_errors) { |
| | 2404 | var wip_errors: std.zig.ErrorBundle.Wip = undefined; |
| | 2405 | wip_errors.init(gpa) catch unreachable; |
| | 2406 | Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable; |
| | 2407 | std.debug.print("compile error during Sema:\n", .{}); |
| | 2408 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; |
| | 2409 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); |
| | 2410 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2402 | } | 2411 | } |
| | 2412 | |
| 2403 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); | 2413 | try mod.failed_decls.ensureUnusedCapacity(gpa, 1); |
| 2404 | try mod.failed_files.ensureUnusedCapacity(gpa, 1); | 2414 | try mod.failed_files.ensureUnusedCapacity(gpa, 1); |
| 2405 | | 2415 | |
| 2406 | const max_references = blk: { | 2416 | if (block) |start_block| { |
| 2407 | if (mod.comp.reference_trace) |num| break :blk num; | 2417 | var block_it = start_block; |
| 2408 | // Do not add multiple traces without explicit request. | 2418 | while (block_it.inlining) |inlining| { |
| 2409 | if (mod.failed_decls.count() != 0) break :ref; | 2419 | try sema.errNote( |
| 2410 | break :blk default_reference_trace_len; | 2420 | inlining.call_block, |
| 2411 | }; | 2421 | inlining.call_src, |
| | 2422 | err_msg, |
| | 2423 | "called from here", |
| | 2424 | .{}, |
| | 2425 | ); |
| | 2426 | block_it = inlining.call_block; |
| | 2427 | } |
| 2412 | | 2428 | |
| 2413 | var referenced_by = if (sema.owner_func_index != .none) | 2429 | const max_references = refs: { |
| 2414 | mod.funcOwnerDeclIndex(sema.owner_func_index) | 2430 | if (mod.comp.reference_trace) |num| break :refs num; |
| 2415 | else | 2431 | // Do not add multiple traces without explicit request. |
| 2416 | sema.owner_decl_index; | 2432 | if (mod.failed_decls.count() > 0) break :ref; |
| 2417 | var reference_stack = std.ArrayList(Module.ErrorMsg.Trace).init(gpa); | 2433 | break :refs default_reference_trace_len; |
| 2418 | defer reference_stack.deinit(); | 2434 | }; |
| 2419 | | 2435 | |
| 2420 | // Avoid infinite loops. | 2436 | var referenced_by = if (sema.owner_func_index != .none) |
| 2421 | var seen = std.AutoHashMap(Decl.Index, void).init(gpa); | 2437 | mod.funcOwnerDeclIndex(sema.owner_func_index) |
| 2422 | defer seen.deinit(); | 2438 | else |
| 2423 | | 2439 | sema.owner_decl_index; |
| 2424 | var cur_reference_trace: u32 = 0; | 2440 | var reference_stack = std.ArrayList(Module.ErrorMsg.Trace).init(gpa); |
| 2425 | while (sema.mod.reference_table.get(referenced_by)) |ref| : (cur_reference_trace += 1) { | 2441 | defer reference_stack.deinit(); |
| 2426 | const gop = try seen.getOrPut(ref.referencer); | 2442 | |
| 2427 | if (gop.found_existing) break; | 2443 | // Avoid infinite loops. |
| 2428 | if (cur_reference_trace < max_references) { | 2444 | var seen = std.AutoHashMap(Decl.Index, void).init(gpa); |
| 2429 | const decl = sema.mod.declPtr(ref.referencer); | 2445 | defer seen.deinit(); |
| 2430 | try reference_stack.append(.{ | 2446 | |
| 2431 | .decl = decl.name.toOptional(), | 2447 | while (mod.reference_table.get(referenced_by)) |ref| { |
| 2432 | .src_loc = ref.src.toSrcLoc(decl, mod), | 2448 | const gop = try seen.getOrPut(ref.referencer); |
| 2433 | }); | 2449 | if (gop.found_existing) break; |
| | 2450 | if (reference_stack.items.len < max_references) { |
| | 2451 | const decl = mod.declPtr(ref.referencer); |
| | 2452 | try reference_stack.append(.{ |
| | 2453 | .decl = decl.name, |
| | 2454 | .src_loc = ref.src.toSrcLoc(decl, mod), |
| | 2455 | }); |
| | 2456 | } |
| | 2457 | referenced_by = ref.referencer; |
| 2434 | } | 2458 | } |
| 2435 | referenced_by = ref.referencer; | 2459 | err_msg.reference_trace = try reference_stack.toOwnedSlice(); |
| 2436 | } | 2460 | err_msg.hidden_references = @intCast(seen.count() -| max_references); |
| 2437 | if (sema.mod.comp.reference_trace == null and cur_reference_trace > 0) { | | |
| 2438 | try reference_stack.append(.{ | | |
| 2439 | .decl = .none, | | |
| 2440 | .src_loc = undefined, | | |
| 2441 | .hidden = 0, | | |
| 2442 | }); | | |
| 2443 | } else if (cur_reference_trace > max_references) { | | |
| 2444 | try reference_stack.append(.{ | | |
| 2445 | .decl = undefined, | | |
| 2446 | .src_loc = undefined, | | |
| 2447 | .hidden = cur_reference_trace - max_references, | | |
| 2448 | }); | | |
| 2449 | } | 2461 | } |
| 2450 | err_msg.reference_trace = try reference_stack.toOwnedSlice(); | | |
| 2451 | } | 2462 | } |
| 2452 | const ip = &mod.intern_pool; | 2463 | const ip = &mod.intern_pool; |
| 2453 | if (sema.owner_func_index != .none) { | 2464 | if (sema.owner_func_index != .none) { |
| ... | @@ -2507,8 +2518,10 @@ fn analyzeAsAlign( | ... | @@ -2507,8 +2518,10 @@ fn analyzeAsAlign( |
| 2507 | src: LazySrcLoc, | 2518 | src: LazySrcLoc, |
| 2508 | air_ref: Air.Inst.Ref, | 2519 | air_ref: Air.Inst.Ref, |
| 2509 | ) !Alignment { | 2520 | ) !Alignment { |
| 2510 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known"); | 2521 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{ |
| 2511 | const alignment = @as(u32, @intCast(alignment_big)); // We coerce to u29 in the prev line. | 2522 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 2523 | }); |
| | 2524 | const alignment: u32 = @intCast(alignment_big); // We coerce to u29 in the prev line. |
| 2512 | try sema.validateAlign(block, src, alignment); | 2525 | try sema.validateAlign(block, src, alignment); |
| 2513 | return Alignment.fromNonzeroByteUnits(alignment); | 2526 | return Alignment.fromNonzeroByteUnits(alignment); |
| 2514 | } | 2527 | } |
| ... | @@ -2543,7 +2556,7 @@ fn resolveInt( | ... | @@ -2543,7 +2556,7 @@ fn resolveInt( |
| 2543 | src: LazySrcLoc, | 2556 | src: LazySrcLoc, |
| 2544 | zir_ref: Zir.Inst.Ref, | 2557 | zir_ref: Zir.Inst.Ref, |
| 2545 | dest_ty: Type, | 2558 | dest_ty: Type, |
| 2546 | reason: []const u8, | 2559 | reason: NeededComptimeReason, |
| 2547 | ) !u64 { | 2560 | ) !u64 { |
| 2548 | const air_ref = try sema.resolveInst(zir_ref); | 2561 | const air_ref = try sema.resolveInst(zir_ref); |
| 2549 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); | 2562 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); |
| ... | @@ -2555,7 +2568,7 @@ fn analyzeAsInt( | ... | @@ -2555,7 +2568,7 @@ fn analyzeAsInt( |
| 2555 | src: LazySrcLoc, | 2568 | src: LazySrcLoc, |
| 2556 | air_ref: Air.Inst.Ref, | 2569 | air_ref: Air.Inst.Ref, |
| 2557 | dest_ty: Type, | 2570 | dest_ty: Type, |
| 2558 | reason: []const u8, | 2571 | reason: NeededComptimeReason, |
| 2559 | ) !u64 { | 2572 | ) !u64 { |
| 2560 | const mod = sema.mod; | 2573 | const mod = sema.mod; |
| 2561 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); | 2574 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| ... | @@ -2570,7 +2583,7 @@ pub fn resolveInstConst( | ... | @@ -2570,7 +2583,7 @@ pub fn resolveInstConst( |
| 2570 | block: *Block, | 2583 | block: *Block, |
| 2571 | src: LazySrcLoc, | 2584 | src: LazySrcLoc, |
| 2572 | zir_ref: Zir.Inst.Ref, | 2585 | zir_ref: Zir.Inst.Ref, |
| 2573 | reason: []const u8, | 2586 | reason: NeededComptimeReason, |
| 2574 | ) CompileError!TypedValue { | 2587 | ) CompileError!TypedValue { |
| 2575 | const air_ref = try sema.resolveInst(zir_ref); | 2588 | const air_ref = try sema.resolveInst(zir_ref); |
| 2576 | const val = try sema.resolveConstValue(block, src, air_ref, reason); | 2589 | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| ... | @@ -2587,7 +2600,7 @@ pub fn resolveInstValue( | ... | @@ -2587,7 +2600,7 @@ pub fn resolveInstValue( |
| 2587 | block: *Block, | 2600 | block: *Block, |
| 2588 | src: LazySrcLoc, | 2601 | src: LazySrcLoc, |
| 2589 | zir_ref: Zir.Inst.Ref, | 2602 | zir_ref: Zir.Inst.Ref, |
| 2590 | reason: []const u8, | 2603 | reason: NeededComptimeReason, |
| 2591 | ) CompileError!TypedValue { | 2604 | ) CompileError!TypedValue { |
| 2592 | const air_ref = try sema.resolveInst(zir_ref); | 2605 | const air_ref = try sema.resolveInst(zir_ref); |
| 2593 | const val = try sema.resolveValue(block, src, air_ref, reason); | 2606 | const val = try sema.resolveValue(block, src, air_ref, reason); |
| ... | @@ -2742,7 +2755,7 @@ fn coerceResultPtr( | ... | @@ -2742,7 +2755,7 @@ fn coerceResultPtr( |
| 2742 | if (pointee_ty.eql(Type.null, sema.mod)) { | 2755 | if (pointee_ty.eql(Type.null, sema.mod)) { |
| 2743 | const null_inst = Air.internedToRef(Value.null.toIntern()); | 2756 | const null_inst = Air.internedToRef(Value.null.toIntern()); |
| 2744 | _ = try block.addBinOp(.store, new_ptr, null_inst); | 2757 | _ = try block.addBinOp(.store, new_ptr, null_inst); |
| 2745 | return Air.Inst.Ref.void_value; | 2758 | return .void_value; |
| 2746 | } | 2759 | } |
| 2747 | return sema.bitCast(block, ptr_ty, new_ptr, src, null); | 2760 | return sema.bitCast(block, ptr_ty, new_ptr, src, null); |
| 2748 | } | 2761 | } |
| ... | @@ -2815,7 +2828,7 @@ pub fn analyzeStructDecl( | ... | @@ -2815,7 +2828,7 @@ pub fn analyzeStructDecl( |
| 2815 | const struct_obj = mod.structPtr(struct_index); | 2828 | const struct_obj = mod.structPtr(struct_index); |
| 2816 | const extended = sema.code.instructions.items(.data)[inst].extended; | 2829 | const extended = sema.code.instructions.items(.data)[inst].extended; |
| 2817 | assert(extended.opcode == .struct_decl); | 2830 | assert(extended.opcode == .struct_decl); |
| 2818 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 2831 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2819 | | 2832 | |
| 2820 | struct_obj.known_non_opv = small.known_non_opv; | 2833 | struct_obj.known_non_opv = small.known_non_opv; |
| 2821 | if (small.known_comptime_only) { | 2834 | if (small.known_comptime_only) { |
| ... | @@ -2852,9 +2865,9 @@ fn zirStructDecl( | ... | @@ -2852,9 +2865,9 @@ fn zirStructDecl( |
| 2852 | ) CompileError!Air.Inst.Ref { | 2865 | ) CompileError!Air.Inst.Ref { |
| 2853 | const mod = sema.mod; | 2866 | const mod = sema.mod; |
| 2854 | const gpa = sema.gpa; | 2867 | const gpa = sema.gpa; |
| 2855 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 2868 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2856 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 2869 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 2857 | const node_offset = @as(i32, @bitCast(sema.code.extra[extended.operand])); | 2870 | const node_offset: i32 = @bitCast(sema.code.extra[extended.operand]); |
| 2858 | break :blk LazySrcLoc.nodeOffset(node_offset); | 2871 | break :blk LazySrcLoc.nodeOffset(node_offset); |
| 2859 | } else sema.src; | 2872 | } else sema.src; |
| 2860 | | 2873 | |
| ... | @@ -2972,7 +2985,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2972,7 +2985,7 @@ fn createAnonymousDeclTypeNamed( |
| 2972 | // If not then this is a struct type being returned from a non-generic | 2985 | // 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 | 2986 | // function and the name doesn't matter since it will later |
| 2974 | // result in a compile error. | 2987 | // result in a compile error. |
| 2975 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch | 2988 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch |
| 2976 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); | 2989 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); |
| 2977 | | 2990 | |
| 2978 | if (arg_i != 0) try writer.writeByte(','); | 2991 | if (arg_i != 0) try writer.writeByte(','); |
| ... | @@ -3214,20 +3227,22 @@ fn zirEnumDecl( | ... | @@ -3214,20 +3227,22 @@ fn zirEnumDecl( |
| 3214 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); | 3227 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 3215 | break :msg msg; | 3228 | break :msg msg; |
| 3216 | }; | 3229 | }; |
| 3217 | return sema.failWithOwnedErrorMsg(msg); | 3230 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3218 | } | 3231 | } |
| 3219 | | 3232 | |
| 3220 | const tag_overflow = if (has_tag_value) overflow: { | 3233 | const tag_overflow = if (has_tag_value) overflow: { |
| 3221 | const tag_val_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 3234 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3222 | extra_index += 1; | 3235 | extra_index += 1; |
| 3223 | const tag_inst = try sema.resolveInst(tag_val_ref); | 3236 | const tag_inst = try sema.resolveInst(tag_val_ref); |
| 3224 | last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) { | 3237 | last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { |
| 3225 | error.NeededSourceLocation => { | 3238 | error.NeededSourceLocation => { |
| 3226 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3239 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3227 | .index = field_i, | 3240 | .index = field_i, |
| 3228 | .range = .value, | 3241 | .range = .value, |
| 3229 | }).lazy; | 3242 | }).lazy; |
| 3230 | _ = try sema.resolveConstValue(block, value_src, tag_inst, "enum tag value must be comptime-known"); | 3243 | _ = try sema.resolveConstValue(block, value_src, tag_inst, .{ |
| | 3244 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| | 3245 | }); |
| 3231 | unreachable; | 3246 | unreachable; |
| 3232 | }, | 3247 | }, |
| 3233 | else => |e| return e, | 3248 | else => |e| return e, |
| ... | @@ -3246,7 +3261,7 @@ fn zirEnumDecl( | ... | @@ -3246,7 +3261,7 @@ fn zirEnumDecl( |
| 3246 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3261 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); |
| 3247 | break :msg msg; | 3262 | break :msg msg; |
| 3248 | }; | 3263 | }; |
| 3249 | return sema.failWithOwnedErrorMsg(msg); | 3264 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3250 | } | 3265 | } |
| 3251 | break :overflow false; | 3266 | break :overflow false; |
| 3252 | } else if (any_values) overflow: { | 3267 | } else if (any_values) overflow: { |
| ... | @@ -3265,7 +3280,7 @@ fn zirEnumDecl( | ... | @@ -3265,7 +3280,7 @@ fn zirEnumDecl( |
| 3265 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3280 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); |
| 3266 | break :msg msg; | 3281 | break :msg msg; |
| 3267 | }; | 3282 | }; |
| 3268 | return sema.failWithOwnedErrorMsg(msg); | 3283 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3269 | } | 3284 | } |
| 3270 | break :overflow false; | 3285 | break :overflow false; |
| 3271 | } else overflow: { | 3286 | } else overflow: { |
| ... | @@ -3283,7 +3298,7 @@ fn zirEnumDecl( | ... | @@ -3283,7 +3298,7 @@ fn zirEnumDecl( |
| 3283 | const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{ | 3298 | const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{ |
| 3284 | last_tag_val.?.fmtValue(int_tag_ty, mod), int_tag_ty.fmt(mod), | 3299 | last_tag_val.?.fmtValue(int_tag_ty, mod), int_tag_ty.fmt(mod), |
| 3285 | }); | 3300 | }); |
| 3286 | return sema.failWithOwnedErrorMsg(msg); | 3301 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3287 | } | 3302 | } |
| 3288 | } | 3303 | } |
| 3289 | return decl_val; | 3304 | return decl_val; |
| ... | @@ -3300,11 +3315,11 @@ fn zirUnionDecl( | ... | @@ -3300,11 +3315,11 @@ fn zirUnionDecl( |
| 3300 | | 3315 | |
| 3301 | const mod = sema.mod; | 3316 | const mod = sema.mod; |
| 3302 | const gpa = sema.gpa; | 3317 | const gpa = sema.gpa; |
| 3303 | const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small)); | 3318 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 3304 | var extra_index: usize = extended.operand; | 3319 | var extra_index: usize = extended.operand; |
| 3305 | | 3320 | |
| 3306 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 3321 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 3307 | const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index])); | 3322 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); |
| 3308 | extra_index += 1; | 3323 | extra_index += 1; |
| 3309 | break :blk LazySrcLoc.nodeOffset(node_offset); | 3324 | break :blk LazySrcLoc.nodeOffset(node_offset); |
| 3310 | } else sema.src; | 3325 | } else sema.src; |
| ... | @@ -3398,11 +3413,11 @@ fn zirOpaqueDecl( | ... | @@ -3398,11 +3413,11 @@ fn zirOpaqueDecl( |
| 3398 | defer tracy.end(); | 3413 | defer tracy.end(); |
| 3399 | | 3414 | |
| 3400 | const mod = sema.mod; | 3415 | const mod = sema.mod; |
| 3401 | const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small)); | 3416 | const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small); |
| 3402 | var extra_index: usize = extended.operand; | 3417 | var extra_index: usize = extended.operand; |
| 3403 | | 3418 | |
| 3404 | const src: LazySrcLoc = if (small.has_src_node) blk: { | 3419 | const src: LazySrcLoc = if (small.has_src_node) blk: { |
| 3405 | const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index])); | 3420 | const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); |
| 3406 | extra_index += 1; | 3421 | extra_index += 1; |
| 3407 | break :blk LazySrcLoc.nodeOffset(node_offset); | 3422 | break :blk LazySrcLoc.nodeOffset(node_offset); |
| 3408 | } else sema.src; | 3423 | } else sema.src; |
| ... | @@ -3469,7 +3484,7 @@ fn zirErrorSetDecl( | ... | @@ -3469,7 +3484,7 @@ fn zirErrorSetDecl( |
| 3469 | var names: InferredErrorSet.NameMap = .{}; | 3484 | var names: InferredErrorSet.NameMap = .{}; |
| 3470 | try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len); | 3485 | try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len); |
| 3471 | | 3486 | |
| 3472 | var extra_index = @as(u32, @intCast(extra.end)); | 3487 | var extra_index: u32 = @intCast(extra.end); |
| 3473 | const extra_index_end = extra_index + (extra.data.fields_len * 2); | 3488 | const extra_index_end = extra_index + (extra.data.fields_len * 2); |
| 3474 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string | 3489 | while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string |
| 3475 | const str_index = sema.code.extra[extra_index]; | 3490 | const str_index = sema.code.extra[extra_index]; |
| ... | @@ -3556,7 +3571,7 @@ fn ensureResultUsed( | ... | @@ -3556,7 +3571,7 @@ fn ensureResultUsed( |
| 3556 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3571 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3557 | break :msg msg; | 3572 | break :msg msg; |
| 3558 | }; | 3573 | }; |
| 3559 | return sema.failWithOwnedErrorMsg(msg); | 3574 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3560 | }, | 3575 | }, |
| 3561 | else => { | 3576 | else => { |
| 3562 | const msg = msg: { | 3577 | const msg = msg: { |
| ... | @@ -3566,7 +3581,7 @@ fn ensureResultUsed( | ... | @@ -3566,7 +3581,7 @@ fn ensureResultUsed( |
| 3566 | try sema.errNote(block, src, msg, "this error can be suppressed by assigning the value to '_'", .{}); | 3581 | try sema.errNote(block, src, msg, "this error can be suppressed by assigning the value to '_'", .{}); |
| 3567 | break :msg msg; | 3582 | break :msg msg; |
| 3568 | }; | 3583 | }; |
| 3569 | return sema.failWithOwnedErrorMsg(msg); | 3584 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3570 | }, | 3585 | }, |
| 3571 | } | 3586 | } |
| 3572 | } | 3587 | } |
| ... | @@ -3588,7 +3603,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3588,7 +3603,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3588 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3603 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3589 | break :msg msg; | 3604 | break :msg msg; |
| 3590 | }; | 3605 | }; |
| 3591 | return sema.failWithOwnedErrorMsg(msg); | 3606 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3592 | }, | 3607 | }, |
| 3593 | else => return, | 3608 | else => return, |
| 3594 | } | 3609 | } |
| ... | @@ -3616,7 +3631,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index | ... | @@ -3616,7 +3631,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3616 | try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{}); | 3631 | try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{}); |
| 3617 | break :msg msg; | 3632 | break :msg msg; |
| 3618 | }; | 3633 | }; |
| 3619 | return sema.failWithOwnedErrorMsg(msg); | 3634 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3620 | } | 3635 | } |
| 3621 | } | 3636 | } |
| 3622 | | 3637 | |
| ... | @@ -3669,18 +3684,18 @@ fn zirAllocExtended( | ... | @@ -3669,18 +3684,18 @@ fn zirAllocExtended( |
| 3669 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); | 3684 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 3670 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | 3685 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; |
| 3671 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; | 3686 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; |
| 3672 | const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small)); | 3687 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); |
| 3673 | | 3688 | |
| 3674 | var extra_index: usize = extra.end; | 3689 | var extra_index: usize = extra.end; |
| 3675 | | 3690 | |
| 3676 | const var_ty: Type = if (small.has_type) blk: { | 3691 | const var_ty: Type = if (small.has_type) blk: { |
| 3677 | const type_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 3692 | const type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3678 | extra_index += 1; | 3693 | extra_index += 1; |
| 3679 | break :blk try sema.resolveType(block, ty_src, type_ref); | 3694 | break :blk try sema.resolveType(block, ty_src, type_ref); |
| 3680 | } else undefined; | 3695 | } else undefined; |
| 3681 | | 3696 | |
| 3682 | const alignment = if (small.has_align) blk: { | 3697 | const alignment = if (small.has_align) blk: { |
| 3683 | const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 3698 | const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3684 | extra_index += 1; | 3699 | extra_index += 1; |
| 3685 | const alignment = try sema.resolveAlign(block, align_src, align_ref); | 3700 | const alignment = try sema.resolveAlign(block, align_src, align_ref); |
| 3686 | break :blk alignment; | 3701 | break :blk alignment; |
| ... | @@ -3698,7 +3713,7 @@ fn zirAllocExtended( | ... | @@ -3698,7 +3713,7 @@ fn zirAllocExtended( |
| 3698 | .is_const = small.is_const, | 3713 | .is_const = small.is_const, |
| 3699 | } }, | 3714 | } }, |
| 3700 | }); | 3715 | }); |
| 3701 | return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1))); | 3716 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); |
| 3702 | } | 3717 | } |
| 3703 | } | 3718 | } |
| 3704 | | 3719 | |
| ... | @@ -3830,7 +3845,7 @@ fn zirAllocInferredComptime( | ... | @@ -3830,7 +3845,7 @@ fn zirAllocInferredComptime( |
| 3830 | .is_const = is_const, | 3845 | .is_const = is_const, |
| 3831 | } }, | 3846 | } }, |
| 3832 | }); | 3847 | }); |
| 3833 | return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1))); | 3848 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); |
| 3834 | } | 3849 | } |
| 3835 | | 3850 | |
| 3836 | fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 3851 | fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -3895,7 +3910,7 @@ fn zirAllocInferred( | ... | @@ -3895,7 +3910,7 @@ fn zirAllocInferred( |
| 3895 | .is_const = is_const, | 3910 | .is_const = is_const, |
| 3896 | } }, | 3911 | } }, |
| 3897 | }); | 3912 | }); |
| 3898 | return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1))); | 3913 | return Air.indexToRef(@intCast(sema.air_instructions.len - 1)); |
| 3899 | } | 3914 | } |
| 3900 | | 3915 | |
| 3901 | const result_index = try block.addInstAsIndex(.{ | 3916 | const result_index = try block.addInstAsIndex(.{ |
| ... | @@ -4147,7 +4162,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -4147,7 +4162,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4147 | .data = .{ .ty_pl = .{ | 4162 | .data = .{ .ty_pl = .{ |
| 4148 | .ty = ty_inst, | 4163 | .ty = ty_inst, |
| 4149 | .payload = sema.addExtraAssumeCapacity(Air.Block{ | 4164 | .payload = sema.addExtraAssumeCapacity(Air.Block{ |
| 4150 | .body_len = @as(u32, @intCast(replacement_block.instructions.items.len)), | 4165 | .body_len = @intCast(replacement_block.instructions.items.len), |
| 4151 | }), | 4166 | }), |
| 4152 | } }, | 4167 | } }, |
| 4153 | }); | 4168 | }); |
| ... | @@ -4231,7 +4246,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4231,7 +4246,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4231 | | 4246 | |
| 4232 | // First pass to look for comptime values. | 4247 | // First pass to look for comptime values. |
| 4233 | for (args, 0..) |zir_arg, i_usize| { | 4248 | for (args, 0..) |zir_arg, i_usize| { |
| 4234 | const i = @as(u32, @intCast(i_usize)); | 4249 | const i: u32 = @intCast(i_usize); |
| 4235 | runtime_arg_lens[i] = .none; | 4250 | runtime_arg_lens[i] = .none; |
| 4236 | if (zir_arg == .none) continue; | 4251 | if (zir_arg == .none) continue; |
| 4237 | const object = try sema.resolveInst(zir_arg); | 4252 | const object = try sema.resolveInst(zir_arg); |
| ... | @@ -4255,7 +4270,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4255,7 +4270,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4255 | try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); | 4270 | try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); |
| 4256 | break :msg msg; | 4271 | break :msg msg; |
| 4257 | }; | 4272 | }; |
| 4258 | return sema.failWithOwnedErrorMsg(msg); | 4273 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4259 | } | 4274 | } |
| 4260 | if (!object_ty.indexableHasLen(mod)) continue; | 4275 | if (!object_ty.indexableHasLen(mod)) continue; |
| 4261 | | 4276 | |
| ... | @@ -4284,7 +4299,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4284,7 +4299,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4284 | }); | 4299 | }); |
| 4285 | break :msg msg; | 4300 | break :msg msg; |
| 4286 | }; | 4301 | }; |
| 4287 | return sema.failWithOwnedErrorMsg(msg); | 4302 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4288 | } | 4303 | } |
| 4289 | } else { | 4304 | } else { |
| 4290 | len = arg_len; | 4305 | len = arg_len; |
| ... | @@ -4302,7 +4317,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4302,7 +4317,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4302 | const msg = try sema.errMsg(block, src, "unbounded for loop", .{}); | 4317 | const msg = try sema.errMsg(block, src, "unbounded for loop", .{}); |
| 4303 | errdefer msg.destroy(gpa); | 4318 | errdefer msg.destroy(gpa); |
| 4304 | for (args, 0..) |zir_arg, i_usize| { | 4319 | for (args, 0..) |zir_arg, i_usize| { |
| 4305 | const i = @as(u32, @intCast(i_usize)); | 4320 | const i: u32 = @intCast(i_usize); |
| 4306 | if (zir_arg == .none) continue; | 4321 | if (zir_arg == .none) continue; |
| 4307 | const object = try sema.resolveInst(zir_arg); | 4322 | const object = try sema.resolveInst(zir_arg); |
| 4308 | const object_ty = sema.typeOf(object); | 4323 | const object_ty = sema.typeOf(object); |
| ... | @@ -4322,7 +4337,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4322,7 +4337,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4322 | } | 4337 | } |
| 4323 | break :msg msg; | 4338 | break :msg msg; |
| 4324 | }; | 4339 | }; |
| 4325 | return sema.failWithOwnedErrorMsg(msg); | 4340 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4326 | } | 4341 | } |
| 4327 | | 4342 | |
| 4328 | // Now for the runtime checks. | 4343 | // Now for the runtime checks. |
| ... | @@ -4497,7 +4512,7 @@ fn validateUnionInit( | ... | @@ -4497,7 +4512,7 @@ fn validateUnionInit( |
| 4497 | try sema.addDeclaredHereNote(msg, union_ty); | 4512 | try sema.addDeclaredHereNote(msg, union_ty); |
| 4498 | break :msg msg; | 4513 | break :msg msg; |
| 4499 | }; | 4514 | }; |
| 4500 | return sema.failWithOwnedErrorMsg(msg); | 4515 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4501 | } | 4516 | } |
| 4502 | | 4517 | |
| 4503 | if (block.is_comptime and | 4518 | if (block.is_comptime and |
| ... | @@ -4611,7 +4626,9 @@ fn validateUnionInit( | ... | @@ -4611,7 +4626,9 @@ fn validateUnionInit( |
| 4611 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4626 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4612 | return; | 4627 | return; |
| 4613 | } else if (try sema.typeRequiresComptime(union_ty)) { | 4628 | } 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"); | 4629 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| | 4630 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", |
| | 4631 | }); |
| 4615 | } | 4632 | } |
| 4616 | | 4633 | |
| 4617 | const new_tag = Air.internedToRef(tag_val.toIntern()); | 4634 | const new_tag = Air.internedToRef(tag_val.toIntern()); |
| ... | @@ -4662,7 +4679,7 @@ fn validateStructInit( | ... | @@ -4662,7 +4679,7 @@ fn validateStructInit( |
| 4662 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); | 4679 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 4663 | break :msg msg; | 4680 | break :msg msg; |
| 4664 | }; | 4681 | }; |
| 4665 | return sema.failWithOwnedErrorMsg(msg); | 4682 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4666 | } | 4683 | } |
| 4667 | found_fields[field_index.*] = field_ptr; | 4684 | found_fields[field_index.*] = field_ptr; |
| 4668 | } | 4685 | } |
| ... | @@ -4705,9 +4722,9 @@ fn validateStructInit( | ... | @@ -4705,9 +4722,9 @@ fn validateStructInit( |
| 4705 | | 4722 | |
| 4706 | const field_src = init_src; // TODO better source location | 4723 | const field_src = init_src; // TODO better source location |
| 4707 | const default_field_ptr = if (struct_ty.isTuple(mod)) | 4724 | const default_field_ptr = if (struct_ty.isTuple(mod)) |
| 4708 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true) | 4725 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true) |
| 4709 | else | 4726 | else |
| 4710 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true); | 4727 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true); |
| 4711 | const init = Air.internedToRef(default_val.toIntern()); | 4728 | const init = Air.internedToRef(default_val.toIntern()); |
| 4712 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); | 4729 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); |
| 4713 | } | 4730 | } |
| ... | @@ -4723,7 +4740,7 @@ fn validateStructInit( | ... | @@ -4723,7 +4740,7 @@ fn validateStructInit( |
| 4723 | ); | 4740 | ); |
| 4724 | } | 4741 | } |
| 4725 | root_msg = null; | 4742 | root_msg = null; |
| 4726 | return sema.failWithOwnedErrorMsg(msg); | 4743 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4727 | } | 4744 | } |
| 4728 | | 4745 | |
| 4729 | return; | 4746 | return; |
| ... | @@ -4806,7 +4823,9 @@ fn validateStructInit( | ... | @@ -4806,7 +4823,9 @@ fn validateStructInit( |
| 4806 | field_values[i] = val.toIntern(); | 4823 | field_values[i] = val.toIntern(); |
| 4807 | } else if (require_comptime) { | 4824 | } else if (require_comptime) { |
| 4808 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | 4825 | 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"); | 4826 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ |
| | 4827 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| | 4828 | }); |
| 4810 | } else { | 4829 | } else { |
| 4811 | struct_is_comptime = false; | 4830 | struct_is_comptime = false; |
| 4812 | } | 4831 | } |
| ... | @@ -4851,7 +4870,7 @@ fn validateStructInit( | ... | @@ -4851,7 +4870,7 @@ fn validateStructInit( |
| 4851 | ); | 4870 | ); |
| 4852 | } | 4871 | } |
| 4853 | root_msg = null; | 4872 | root_msg = null; |
| 4854 | return sema.failWithOwnedErrorMsg(msg); | 4873 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4855 | } | 4874 | } |
| 4856 | | 4875 | |
| 4857 | if (struct_is_comptime) { | 4876 | if (struct_is_comptime) { |
| ... | @@ -4911,9 +4930,9 @@ fn validateStructInit( | ... | @@ -4911,9 +4930,9 @@ fn validateStructInit( |
| 4911 | | 4930 | |
| 4912 | const field_src = init_src; // TODO better source location | 4931 | const field_src = init_src; // TODO better source location |
| 4913 | const default_field_ptr = if (struct_ty.isTuple(mod)) | 4932 | const default_field_ptr = if (struct_ty.isTuple(mod)) |
| 4914 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true) | 4933 | try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true) |
| 4915 | else | 4934 | else |
| 4916 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true); | 4935 | try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true); |
| 4917 | const init = Air.internedToRef(field_values[i]); | 4936 | const init = Air.internedToRef(field_values[i]); |
| 4918 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); | 4937 | try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store); |
| 4919 | } | 4938 | } |
| ... | @@ -4955,7 +4974,7 @@ fn zirValidateArrayInit( | ... | @@ -4955,7 +4974,7 @@ fn zirValidateArrayInit( |
| 4955 | | 4974 | |
| 4956 | if (root_msg) |msg| { | 4975 | if (root_msg) |msg| { |
| 4957 | root_msg = null; | 4976 | root_msg = null; |
| 4958 | return sema.failWithOwnedErrorMsg(msg); | 4977 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4959 | } | 4978 | } |
| 4960 | }, | 4979 | }, |
| 4961 | .Array => { | 4980 | .Array => { |
| ... | @@ -5168,7 +5187,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -5168,7 +5187,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5168 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty); | 5187 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty); |
| 5169 | break :msg msg; | 5188 | break :msg msg; |
| 5170 | }; | 5189 | }; |
| 5171 | return sema.failWithOwnedErrorMsg(msg); | 5190 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5172 | } | 5191 | } |
| 5173 | } | 5192 | } |
| 5174 | | 5193 | |
| ... | @@ -5200,7 +5219,7 @@ fn failWithBadMemberAccess( | ... | @@ -5200,7 +5219,7 @@ fn failWithBadMemberAccess( |
| 5200 | try sema.addDeclaredHereNote(msg, agg_ty); | 5219 | try sema.addDeclaredHereNote(msg, agg_ty); |
| 5201 | break :msg msg; | 5220 | break :msg msg; |
| 5202 | }; | 5221 | }; |
| 5203 | return sema.failWithOwnedErrorMsg(msg); | 5222 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5204 | } | 5223 | } |
| 5205 | | 5224 | |
| 5206 | fn failWithBadStructFieldAccess( | 5225 | fn failWithBadStructFieldAccess( |
| ... | @@ -5226,7 +5245,7 @@ fn failWithBadStructFieldAccess( | ... | @@ -5226,7 +5245,7 @@ fn failWithBadStructFieldAccess( |
| 5226 | try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{}); | 5245 | try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{}); |
| 5227 | break :msg msg; | 5246 | break :msg msg; |
| 5228 | }; | 5247 | }; |
| 5229 | return sema.failWithOwnedErrorMsg(msg); | 5248 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5230 | } | 5249 | } |
| 5231 | | 5250 | |
| 5232 | fn failWithBadUnionFieldAccess( | 5251 | fn failWithBadUnionFieldAccess( |
| ... | @@ -5253,7 +5272,7 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5253,7 +5272,7 @@ fn failWithBadUnionFieldAccess( |
| 5253 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{}); | 5272 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{}); |
| 5254 | break :msg msg; | 5273 | break :msg msg; |
| 5255 | }; | 5274 | }; |
| 5256 | return sema.failWithOwnedErrorMsg(msg); | 5275 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5257 | } | 5276 | } |
| 5258 | | 5277 | |
| 5259 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { | 5278 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { |
| ... | @@ -5331,13 +5350,17 @@ fn storeToInferredAllocComptime( | ... | @@ -5331,13 +5350,17 @@ fn storeToInferredAllocComptime( |
| 5331 | return; | 5350 | return; |
| 5332 | } | 5351 | } |
| 5333 | | 5352 | |
| 5334 | return sema.failWithNeededComptime(block, src, "value being stored to a comptime variable must be comptime-known"); | 5353 | return sema.failWithNeededComptime(block, src, .{ |
| | 5354 | .needed_comptime_reason = "value being stored to a comptime variable must be comptime-known", |
| | 5355 | }); |
| 5335 | } | 5356 | } |
| 5336 | | 5357 | |
| 5337 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5358 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5338 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 5359 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5339 | const src = inst_data.src(); | 5360 | const src = inst_data.src(); |
| 5340 | const quota = @as(u32, @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known"))); | 5361 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ |
| | 5362 | .needed_comptime_reason = "eval branch quota must be comptime-known", |
| | 5363 | })); |
| 5341 | sema.branch_quota = @max(sema.branch_quota, quota); | 5364 | sema.branch_quota = @max(sema.branch_quota, quota); |
| 5342 | } | 5365 | } |
| 5343 | | 5366 | |
| ... | @@ -5479,7 +5502,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5479,7 +5502,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5479 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 5502 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5480 | const src = inst_data.src(); | 5503 | const src = inst_data.src(); |
| 5481 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5504 | 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"); | 5505 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| | 5506 | .needed_comptime_reason = "compile error string must be comptime-known", |
| | 5507 | }); |
| 5483 | return sema.fail(block, src, "{s}", .{msg}); | 5508 | return sema.fail(block, src, "{s}", .{msg}); |
| 5484 | } | 5509 | } |
| 5485 | | 5510 | |
| ... | @@ -5520,7 +5545,7 @@ fn zirCompileLog( | ... | @@ -5520,7 +5545,7 @@ fn zirCompileLog( |
| 5520 | if (!gop.found_existing) { | 5545 | if (!gop.found_existing) { |
| 5521 | gop.value_ptr.* = src_node; | 5546 | gop.value_ptr.* = src_node; |
| 5522 | } | 5547 | } |
| 5523 | return Air.Inst.Ref.void_value; | 5548 | return .void_value; |
| 5524 | } | 5549 | } |
| 5525 | | 5550 | |
| 5526 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { | 5551 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { |
| ... | @@ -5558,7 +5583,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5558,7 +5583,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5558 | // Reserve space for a Loop instruction so that generated Break instructions can | 5583 | // Reserve space for a Loop instruction so that generated Break instructions can |
| 5559 | // point to it, even if it doesn't end up getting used because the code ends up being | 5584 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 5560 | // comptime evaluated. | 5585 | // comptime evaluated. |
| 5561 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 5586 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 5562 | const loop_inst = block_inst + 1; | 5587 | const loop_inst = block_inst + 1; |
| 5563 | try sema.air_instructions.ensureUnusedCapacity(gpa, 2); | 5588 | try sema.air_instructions.ensureUnusedCapacity(gpa, 2); |
| 5564 | sema.air_instructions.appendAssumeCapacity(.{ | 5589 | sema.air_instructions.appendAssumeCapacity(.{ |
| ... | @@ -5606,7 +5631,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5606,7 +5631,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5606 | | 5631 | |
| 5607 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len); | 5632 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len); |
| 5608 | sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity( | 5633 | sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity( |
| 5609 | Air.Block{ .body_len = @as(u32, @intCast(loop_block_len)) }, | 5634 | Air.Block{ .body_len = @intCast(loop_block_len) }, |
| 5610 | ); | 5635 | ); |
| 5611 | sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items); | 5636 | sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items); |
| 5612 | } | 5637 | } |
| ... | @@ -5713,7 +5738,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5713,7 +5738,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5713 | } | 5738 | } |
| 5714 | break :msg msg; | 5739 | break :msg msg; |
| 5715 | }; | 5740 | }; |
| 5716 | return sema.failWithOwnedErrorMsg(msg); | 5741 | return sema.failWithOwnedErrorMsg(&child_block, msg); |
| 5717 | } | 5742 | } |
| 5718 | const c_import_pkg = Package.create( | 5743 | const c_import_pkg = Package.create( |
| 5719 | sema.gpa, | 5744 | sema.gpa, |
| ... | @@ -5756,7 +5781,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -5756,7 +5781,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 5756 | // Reserve space for a Block instruction so that generated Break instructions can | 5781 | // Reserve space for a Block instruction so that generated Break instructions can |
| 5757 | // point to it, even if it doesn't end up getting used because the code ends up being | 5782 | // point to it, even if it doesn't end up getting used because the code ends up being |
| 5758 | // comptime evaluated or is an unlabeled block. | 5783 | // comptime evaluated or is an unlabeled block. |
| 5759 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 5784 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 5760 | try sema.air_instructions.append(gpa, .{ | 5785 | try sema.air_instructions.append(gpa, .{ |
| 5761 | .tag = .block, | 5786 | .tag = .block, |
| 5762 | .data = undefined, | 5787 | .data = undefined, |
| ... | @@ -5894,7 +5919,7 @@ fn analyzeBlockBody( | ... | @@ -5894,7 +5919,7 @@ fn analyzeBlockBody( |
| 5894 | | 5919 | |
| 5895 | break :msg msg; | 5920 | break :msg msg; |
| 5896 | }; | 5921 | }; |
| 5897 | return sema.failWithOwnedErrorMsg(msg); | 5922 | return sema.failWithOwnedErrorMsg(child_block, msg); |
| 5898 | } | 5923 | } |
| 5899 | const ty_inst = Air.internedToRef(resolved_ty.toIntern()); | 5924 | const ty_inst = Air.internedToRef(resolved_ty.toIntern()); |
| 5900 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + | 5925 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + |
| ... | @@ -5902,7 +5927,7 @@ fn analyzeBlockBody( | ... | @@ -5902,7 +5927,7 @@ fn analyzeBlockBody( |
| 5902 | sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{ | 5927 | sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{ |
| 5903 | .ty = ty_inst, | 5928 | .ty = ty_inst, |
| 5904 | .payload = sema.addExtraAssumeCapacity(Air.Block{ | 5929 | .payload = sema.addExtraAssumeCapacity(Air.Block{ |
| 5905 | .body_len = @as(u32, @intCast(child_block.instructions.items.len)), | 5930 | .body_len = @intCast(child_block.instructions.items.len), |
| 5906 | }), | 5931 | }), |
| 5907 | } }; | 5932 | } }; |
| 5908 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); | 5933 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); |
| ... | @@ -5929,15 +5954,15 @@ fn analyzeBlockBody( | ... | @@ -5929,15 +5954,15 @@ fn analyzeBlockBody( |
| 5929 | | 5954 | |
| 5930 | // Convert the br instruction to a block instruction that has the coercion | 5955 | // Convert the br instruction to a block instruction that has the coercion |
| 5931 | // and then a new br inside that returns the coerced instruction. | 5956 | // and then a new br inside that returns the coerced instruction. |
| 5932 | const sub_block_len = @as(u32, @intCast(coerce_block.instructions.items.len + 1)); | 5957 | const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1); |
| 5933 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + | 5958 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + |
| 5934 | sub_block_len); | 5959 | sub_block_len); |
| 5935 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); | 5960 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 5936 | const sub_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 5961 | const sub_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 5937 | | 5962 | |
| 5938 | sema.air_instructions.items(.tag)[br] = .block; | 5963 | sema.air_instructions.items(.tag)[br] = .block; |
| 5939 | sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{ | 5964 | sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{ |
| 5940 | .ty = Air.Inst.Ref.noreturn_type, | 5965 | .ty = .noreturn_type, |
| 5941 | .payload = sema.addExtraAssumeCapacity(Air.Block{ | 5966 | .payload = sema.addExtraAssumeCapacity(Air.Block{ |
| 5942 | .body_len = sub_block_len, | 5967 | .body_len = sub_block_len, |
| 5943 | }), | 5968 | }), |
| ... | @@ -6001,7 +6026,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6001,7 +6026,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6001 | const src = inst_data.src(); | 6026 | const src = inst_data.src(); |
| 6002 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6027 | 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 }; | 6028 | 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"); | 6029 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ |
| | 6030 | .needed_comptime_reason = "export target must be comptime-known", |
| | 6031 | }); |
| 6005 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { | 6032 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 6006 | error.NeededSourceLocation => { | 6033 | error.NeededSourceLocation => { |
| 6007 | _ = try sema.resolveExportOptions(block, options_src, extra.options); | 6034 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| ... | @@ -6045,7 +6072,7 @@ pub fn analyzeExport( | ... | @@ -6045,7 +6072,7 @@ pub fn analyzeExport( |
| 6045 | try sema.addDeclaredHereNote(msg, exported_decl.ty); | 6072 | try sema.addDeclaredHereNote(msg, exported_decl.ty); |
| 6046 | break :msg msg; | 6073 | break :msg msg; |
| 6047 | }; | 6074 | }; |
| 6048 | return sema.failWithOwnedErrorMsg(msg); | 6075 | return sema.failWithOwnedErrorMsg(block, msg); |
| 6049 | } | 6076 | } |
| 6050 | | 6077 | |
| 6051 | // TODO: some backends might support re-exporting extern decls | 6078 | // TODO: some backends might support re-exporting extern decls |
| ... | @@ -6122,7 +6149,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -6122,7 +6149,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 6122 | try sema.errNote(block, prev_src, msg, "other instance here", .{}); | 6149 | try sema.errNote(block, prev_src, msg, "other instance here", .{}); |
| 6123 | break :msg msg; | 6150 | break :msg msg; |
| 6124 | }; | 6151 | }; |
| 6125 | return sema.failWithOwnedErrorMsg(msg); | 6152 | return sema.failWithOwnedErrorMsg(block, msg); |
| 6126 | } | 6153 | } |
| 6127 | | 6154 | |
| 6128 | const ip = &mod.intern_pool; | 6155 | const ip = &mod.intern_pool; |
| ... | @@ -6140,7 +6167,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6140,7 +6167,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6140 | const ip = &mod.intern_pool; | 6167 | const ip = &mod.intern_pool; |
| 6141 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6168 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6142 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6169 | 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"); | 6170 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ |
| | 6171 | .needed_comptime_reason = "operand to @setCold must be comptime-known", |
| | 6172 | }); |
| 6144 | if (sema.func_index == .none) return; // does nothing outside a function | 6173 | if (sema.func_index == .none) return; // does nothing outside a function |
| 6145 | ip.funcAnalysis(sema.func_index).is_cold = is_cold; | 6174 | ip.funcAnalysis(sema.func_index).is_cold = is_cold; |
| 6146 | } | 6175 | } |
| ... | @@ -6148,13 +6177,17 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6148,13 +6177,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 { | 6177 | 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; | 6178 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6150 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6179 | 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"); | 6180 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ |
| | 6181 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", |
| | 6182 | }); |
| 6152 | } | 6183 | } |
| 6153 | | 6184 | |
| 6154 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6185 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6155 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 6186 | 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 }; | 6187 | 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"); | 6188 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| | 6189 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", |
| | 6190 | }); |
| 6158 | } | 6191 | } |
| 6159 | | 6192 | |
| 6160 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6193 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| ... | @@ -6162,7 +6195,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co | ... | @@ -6162,7 +6195,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co |
| 6162 | | 6195 | |
| 6163 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6196 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6164 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6197 | 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"); | 6198 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ |
| | 6199 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", |
| | 6200 | }); |
| 6166 | | 6201 | |
| 6167 | if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) { | 6202 | if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) { |
| 6168 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); | 6203 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| ... | @@ -6291,7 +6326,7 @@ fn addDbgVar( | ... | @@ -6291,7 +6326,7 @@ fn addDbgVar( |
| 6291 | try sema.queueFullTypeResolution(operand_ty); | 6326 | try sema.queueFullTypeResolution(operand_ty); |
| 6292 | | 6327 | |
| 6293 | // Add the name to the AIR. | 6328 | // Add the name to the AIR. |
| 6294 | const name_extra_index = @as(u32, @intCast(sema.air_extra.items.len)); | 6329 | const name_extra_index: u32 = @intCast(sema.air_extra.items.len); |
| 6295 | const elements_used = name.len / 4 + 1; | 6330 | const elements_used = name.len / 4 + 1; |
| 6296 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used); | 6331 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used); |
| 6297 | const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice()); | 6332 | const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice()); |
| ... | @@ -6431,7 +6466,7 @@ fn lookupInNamespace( | ... | @@ -6431,7 +6466,7 @@ fn lookupInNamespace( |
| 6431 | } | 6466 | } |
| 6432 | break :msg msg; | 6467 | break :msg msg; |
| 6433 | }; | 6468 | }; |
| 6434 | return sema.failWithOwnedErrorMsg(msg); | 6469 | return sema.failWithOwnedErrorMsg(block, msg); |
| 6435 | }, | 6470 | }, |
| 6436 | } | 6471 | } |
| 6437 | } else if (namespace.decls.getKeyAdapted(ident_name, Module.DeclAdapter{ .mod = mod })) |decl_index| { | 6472 | } else if (namespace.decls.getKeyAdapted(ident_name, Module.DeclAdapter{ .mod = mod })) |decl_index| { |
| ... | @@ -6491,7 +6526,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6491,7 +6526,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6491 | .tag = .save_err_return_trace_index, | 6526 | .tag = .save_err_return_trace_index, |
| 6492 | .data = .{ .ty_pl = .{ | 6527 | .data = .{ .ty_pl = .{ |
| 6493 | .ty = Air.internedToRef(stack_trace_ty.toIntern()), | 6528 | .ty = Air.internedToRef(stack_trace_ty.toIntern()), |
| 6494 | .payload = @as(u32, @intCast(field_index)), | 6529 | .payload = @intCast(field_index), |
| 6495 | } }, | 6530 | } }, |
| 6496 | }); | 6531 | }); |
| 6497 | } | 6532 | } |
| ... | @@ -6535,7 +6570,7 @@ fn popErrorReturnTrace( | ... | @@ -6535,7 +6570,7 @@ fn popErrorReturnTrace( |
| 6535 | .tag = .block, | 6570 | .tag = .block, |
| 6536 | .data = .{ | 6571 | .data = .{ |
| 6537 | .ty_pl = .{ | 6572 | .ty_pl = .{ |
| 6538 | .ty = Air.Inst.Ref.void_type, | 6573 | .ty = .void_type, |
| 6539 | .payload = undefined, // updated below | 6574 | .payload = undefined, // updated below |
| 6540 | }, | 6575 | }, |
| 6541 | }, | 6576 | }, |
| ... | @@ -6552,23 +6587,23 @@ fn popErrorReturnTrace( | ... | @@ -6552,23 +6587,23 @@ fn popErrorReturnTrace( |
| 6552 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); | 6587 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); |
| 6553 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); | 6588 | const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true); |
| 6554 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); | 6589 | try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store); |
| 6555 | _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); | 6590 | _ = try then_block.addBr(cond_block_inst, .void_value); |
| 6556 | | 6591 | |
| 6557 | // Otherwise, do nothing | 6592 | // Otherwise, do nothing |
| 6558 | var else_block = block.makeSubBlock(); | 6593 | var else_block = block.makeSubBlock(); |
| 6559 | defer else_block.instructions.deinit(gpa); | 6594 | defer else_block.instructions.deinit(gpa); |
| 6560 | _ = try else_block.addBr(cond_block_inst, Air.Inst.Ref.void_value); | 6595 | _ = try else_block.addBr(cond_block_inst, .void_value); |
| 6561 | | 6596 | |
| 6562 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + | 6597 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + |
| 6563 | then_block.instructions.items.len + else_block.instructions.items.len + | 6598 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 6564 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block | 6599 | @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block |
| 6565 | | 6600 | |
| 6566 | const cond_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 6601 | const cond_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 6567 | try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{ | 6602 | try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{ |
| 6568 | .operand = is_non_error_inst, | 6603 | .operand = is_non_error_inst, |
| 6569 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 6604 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 6570 | .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)), | 6605 | .then_body_len = @intCast(then_block.instructions.items.len), |
| 6571 | .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)), | 6606 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 6572 | }), | 6607 | }), |
| 6573 | } } }); | 6608 | } } }); |
| 6574 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); | 6609 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); |
| ... | @@ -6599,7 +6634,7 @@ fn zirCall( | ... | @@ -6599,7 +6634,7 @@ fn zirCall( |
| 6599 | const extra = sema.code.extraData(ExtraType, inst_data.payload_index); | 6634 | const extra = sema.code.extraData(ExtraType, inst_data.payload_index); |
| 6600 | const args_len = extra.data.flags.args_len; | 6635 | const args_len = extra.data.flags.args_len; |
| 6601 | | 6636 | |
| 6602 | const modifier = @as(std.builtin.CallModifier, @enumFromInt(extra.data.flags.packed_modifier)); | 6637 | const modifier: std.builtin.CallModifier = @enumFromInt(extra.data.flags.packed_modifier); |
| 6603 | const ensure_result_used = extra.data.flags.ensure_result_used; | 6638 | const ensure_result_used = extra.data.flags.ensure_result_used; |
| 6604 | const pop_error_return_trace = extra.data.flags.pop_error_return_trace; | 6639 | const pop_error_return_trace = extra.data.flags.pop_error_return_trace; |
| 6605 | | 6640 | |
| ... | @@ -6678,7 +6713,7 @@ fn zirCall( | ... | @@ -6678,7 +6713,7 @@ fn zirCall( |
| 6678 | .tag = .save_err_return_trace_index, | 6713 | .tag = .save_err_return_trace_index, |
| 6679 | .data = .{ .ty_pl = .{ | 6714 | .data = .{ .ty_pl = .{ |
| 6680 | .ty = Air.internedToRef(stack_trace_ty.toIntern()), | 6715 | .ty = Air.internedToRef(stack_trace_ty.toIntern()), |
| 6681 | .payload = @as(u32, @intCast(field_index)), | 6716 | .payload = @intCast(field_index), |
| 6682 | } }, | 6717 | } }, |
| 6683 | }); | 6718 | }); |
| 6684 | | 6719 | |
| ... | @@ -6725,7 +6760,7 @@ fn checkCallArgumentCount( | ... | @@ -6725,7 +6760,7 @@ fn checkCallArgumentCount( |
| 6725 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); | 6760 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); |
| 6726 | break :msg msg; | 6761 | break :msg msg; |
| 6727 | }; | 6762 | }; |
| 6728 | return sema.failWithOwnedErrorMsg(msg); | 6763 | return sema.failWithOwnedErrorMsg(block, msg); |
| 6729 | } | 6764 | } |
| 6730 | }, | 6765 | }, |
| 6731 | else => {}, | 6766 | else => {}, |
| ... | @@ -6763,7 +6798,7 @@ fn checkCallArgumentCount( | ... | @@ -6763,7 +6798,7 @@ fn checkCallArgumentCount( |
| 6763 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 6798 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); |
| 6764 | break :msg msg; | 6799 | break :msg msg; |
| 6765 | }; | 6800 | }; |
| 6766 | return sema.failWithOwnedErrorMsg(msg); | 6801 | return sema.failWithOwnedErrorMsg(block, msg); |
| 6767 | } | 6802 | } |
| 6768 | | 6803 | |
| 6769 | fn callBuiltin( | 6804 | fn callBuiltin( |
| ... | @@ -7097,7 +7132,7 @@ fn analyzeCall( | ... | @@ -7097,7 +7132,7 @@ fn analyzeCall( |
| 7097 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 7132 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); |
| 7098 | break :msg msg; | 7133 | break :msg msg; |
| 7099 | }; | 7134 | }; |
| 7100 | return sema.failWithOwnedErrorMsg(msg); | 7135 | return sema.failWithOwnedErrorMsg(block, msg); |
| 7101 | } | 7136 | } |
| 7102 | | 7137 | |
| 7103 | const call_tag: Air.Inst.Tag = switch (modifier) { | 7138 | const call_tag: Air.Inst.Tag = switch (modifier) { |
| ... | @@ -7156,7 +7191,7 @@ fn analyzeCall( | ... | @@ -7156,7 +7191,7 @@ fn analyzeCall( |
| 7156 | } | 7191 | } |
| 7157 | break :msg msg; | 7192 | break :msg msg; |
| 7158 | }; | 7193 | }; |
| 7159 | return sema.failWithOwnedErrorMsg(msg); | 7194 | return sema.failWithOwnedErrorMsg(block, msg); |
| 7160 | } | 7195 | } |
| 7161 | | 7196 | |
| 7162 | if (!is_inline_call and is_generic_call) { | 7197 | if (!is_inline_call and is_generic_call) { |
| ... | @@ -7194,10 +7229,10 @@ fn analyzeCall( | ... | @@ -7194,10 +7229,10 @@ fn analyzeCall( |
| 7194 | } | 7229 | } |
| 7195 | | 7230 | |
| 7196 | const result: Air.Inst.Ref = if (is_inline_call) res: { | 7231 | 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| { | 7232 | 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); | 7233 | .needed_comptime_reason = "function being called at comptime must be comptime-known", |
| 7199 | return err; | 7234 | .block_comptime_reason = comptime_reason, |
| 7200 | }; | 7235 | }); |
| 7201 | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { | 7236 | 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", .{ | 7237 | .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 7203 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), | 7238 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| ... | @@ -7225,7 +7260,7 @@ fn analyzeCall( | ... | @@ -7225,7 +7260,7 @@ fn analyzeCall( |
| 7225 | // set to in the `Block`. | 7260 | // set to in the `Block`. |
| 7226 | // This block instruction will be used to capture the return value from the | 7261 | // This block instruction will be used to capture the return value from the |
| 7227 | // inlined function. | 7262 | // inlined function. |
| 7228 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 7263 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 7229 | try sema.air_instructions.append(gpa, .{ | 7264 | try sema.air_instructions.append(gpa, .{ |
| 7230 | .tag = .block, | 7265 | .tag = .block, |
| 7231 | .data = undefined, | 7266 | .data = undefined, |
| ... | @@ -7233,7 +7268,10 @@ fn analyzeCall( | ... | @@ -7233,7 +7268,10 @@ fn analyzeCall( |
| 7233 | // This one is shared among sub-blocks within the same callee, but not | 7268 | // This one is shared among sub-blocks within the same callee, but not |
| 7234 | // shared among the entire inline/comptime call stack. | 7269 | // shared among the entire inline/comptime call stack. |
| 7235 | var inlining: Block.Inlining = .{ | 7270 | var inlining: Block.Inlining = .{ |
| 7236 | .func = .none, | 7271 | .call_block = block, |
| | 7272 | .call_src = call_src, |
| | 7273 | .has_comptime_args = false, |
| | 7274 | .func = module_fn_index, |
| 7237 | .comptime_result = undefined, | 7275 | .comptime_result = undefined, |
| 7238 | .merges = .{ | 7276 | .merges = .{ |
| 7239 | .src_locs = .{}, | 7277 | .src_locs = .{}, |
| ... | @@ -7317,7 +7355,6 @@ fn analyzeCall( | ... | @@ -7317,7 +7355,6 @@ fn analyzeCall( |
| 7317 | const fn_info = ics.callee().code.getFnInfo(module_fn.zir_body_inst); | 7355 | const fn_info = ics.callee().code.getFnInfo(module_fn.zir_body_inst); |
| 7318 | try ics.callee().inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body); | 7356 | try ics.callee().inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body); |
| 7319 | | 7357 | |
| 7320 | var has_comptime_args = false; | | |
| 7321 | var arg_i: u32 = 0; | 7358 | var arg_i: u32 = 0; |
| 7322 | for (fn_info.param_body) |inst| { | 7359 | for (fn_info.param_body) |inst| { |
| 7323 | const opt_noreturn_ref = try analyzeInlineCallArg( | 7360 | const opt_noreturn_ref = try analyzeInlineCallArg( |
| ... | @@ -7333,7 +7370,6 @@ fn analyzeCall( | ... | @@ -7333,7 +7370,6 @@ fn analyzeCall( |
| 7333 | memoized_arg_values, | 7370 | memoized_arg_values, |
| 7334 | func_ty_info, | 7371 | func_ty_info, |
| 7335 | func, | 7372 | func, |
| 7336 | &has_comptime_args, | | |
| 7337 | ); | 7373 | ); |
| 7338 | if (opt_noreturn_ref) |ref| { | 7374 | if (opt_noreturn_ref) |ref| { |
| 7339 | // Analyzing this argument gave a ref of a noreturn type. Terminate argument analysis here. | 7375 | // Analyzing this argument gave a ref of a noreturn type. Terminate argument analysis here. |
| ... | @@ -7345,19 +7381,19 @@ fn analyzeCall( | ... | @@ -7345,19 +7381,19 @@ fn analyzeCall( |
| 7345 | // can just use `sema` directly. | 7381 | // can just use `sema` directly. |
| 7346 | _ = ics.callee(); | 7382 | _ = ics.callee(); |
| 7347 | | 7383 | |
| 7348 | if (!has_comptime_args and module_fn.analysis(ip).state == .sema_failure) | 7384 | if (!inlining.has_comptime_args) { |
| 7349 | return error.AnalysisFail; | 7385 | if (module_fn.analysis(ip).state == .sema_failure) |
| | 7386 | return error.AnalysisFail; |
| 7350 | | 7387 | |
| 7351 | const recursive_msg = "inline call is recursive"; | 7388 | var block_it = block; |
| 7352 | var head = if (!has_comptime_args) block else null; | 7389 | while (block_it.inlining) |parent_inlining| { |
| 7353 | while (head) |some| { | 7390 | if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) { |
| 7354 | const parent_inlining = some.inlining orelse break; | 7391 | const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{}); |
| 7355 | if (parent_inlining.func == module_fn_index) { | 7392 | return sema.failWithOwnedErrorMsg(null, err_msg); |
| 7356 | return sema.fail(block, call_src, recursive_msg, .{}); | 7393 | } |
| | 7394 | block_it = parent_inlining.call_block; |
| 7357 | } | 7395 | } |
| 7358 | head = some.parent; | | |
| 7359 | } | 7396 | } |
| 7360 | if (!has_comptime_args) inlining.func = module_fn_index; | | |
| 7361 | | 7397 | |
| 7362 | // In case it is a generic function with an expression for the return type that depends | 7398 | // In case it is a generic function with an expression for the return type that depends |
| 7363 | // on parameters, we must now do the same for the return type as we just did with | 7399 | // on parameters, we must now do the same for the return type as we just did with |
| ... | @@ -7427,12 +7463,6 @@ fn analyzeCall( | ... | @@ -7427,12 +7463,6 @@ fn analyzeCall( |
| 7427 | const result = result: { | 7463 | const result = result: { |
| 7428 | sema.analyzeBody(&child_block, fn_info.body) catch |err| switch (err) { | 7464 | sema.analyzeBody(&child_block, fn_info.body) catch |err| switch (err) { |
| 7429 | error.ComptimeReturn => break :result inlining.comptime_result, | 7465 | error.ComptimeReturn => break :result inlining.comptime_result, |
| 7430 | error.AnalysisFail => { | | |
| 7431 | const err_msg = sema.err orelse return err; | | |
| 7432 | if (mem.eql(u8, err_msg.msg, recursive_msg)) return err; | | |
| 7433 | try sema.errNote(block, call_src, err_msg, "called from here", .{}); | | |
| 7434 | return err; | | |
| 7435 | }, | | |
| 7436 | else => |e| return e, | 7466 | else => |e| return e, |
| 7437 | }; | 7467 | }; |
| 7438 | break :result try sema.analyzeBlockBody(block, call_src, &child_block, merges); | 7468 | break :result try sema.analyzeBlockBody(block, call_src, &child_block, merges); |
| ... | @@ -7451,7 +7481,7 @@ fn analyzeCall( | ... | @@ -7451,7 +7481,7 @@ fn analyzeCall( |
| 7451 | } | 7481 | } |
| 7452 | | 7482 | |
| 7453 | if (should_memoize and is_comptime_call) { | 7483 | if (should_memoize and is_comptime_call) { |
| 7454 | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, ""); | 7484 | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined); |
| 7455 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); | 7485 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); |
| 7456 | | 7486 | |
| 7457 | // Transform ad-hoc inferred error set types into concrete error sets. | 7487 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | @@ -7523,7 +7553,7 @@ fn analyzeCall( | ... | @@ -7523,7 +7553,7 @@ fn analyzeCall( |
| 7523 | .data = .{ .pl_op = .{ | 7553 | .data = .{ .pl_op = .{ |
| 7524 | .operand = func, | 7554 | .operand = func, |
| 7525 | .payload = sema.addExtraAssumeCapacity(Air.Call{ | 7555 | .payload = sema.addExtraAssumeCapacity(Air.Call{ |
| 7526 | .args_len = @as(u32, @intCast(args.len)), | 7556 | .args_len = @intCast(args.len), |
| 7527 | }), | 7557 | }), |
| 7528 | } }, | 7558 | } }, |
| 7529 | }); | 7559 | }); |
| ... | @@ -7549,11 +7579,11 @@ fn analyzeCall( | ... | @@ -7549,11 +7579,11 @@ fn analyzeCall( |
| 7549 | } | 7579 | } |
| 7550 | } | 7580 | } |
| 7551 | try sema.safetyPanic(block, call_src, .noreturn_returned); | 7581 | try sema.safetyPanic(block, call_src, .noreturn_returned); |
| 7552 | return Air.Inst.Ref.unreachable_value; | 7582 | return .unreachable_value; |
| 7553 | } | 7583 | } |
| 7554 | if (func_ty_info.return_type == .noreturn_type) { | 7584 | if (func_ty_info.return_type == .noreturn_type) { |
| 7555 | _ = try block.addNoOp(.unreach); | 7585 | _ = try block.addNoOp(.unreach); |
| 7556 | return Air.Inst.Ref.unreachable_value; | 7586 | return .unreachable_value; |
| 7557 | } | 7587 | } |
| 7558 | break :res func_inst; | 7588 | break :res func_inst; |
| 7559 | }; | 7589 | }; |
| ... | @@ -7580,7 +7610,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ | ... | @@ -7580,7 +7610,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ |
| 7580 | }); | 7610 | }); |
| 7581 | } | 7611 | } |
| 7582 | _ = try block.addUnOp(.ret, result); | 7612 | _ = try block.addUnOp(.ret, result); |
| 7583 | return Air.Inst.Ref.unreachable_value; | 7613 | return .unreachable_value; |
| 7584 | } | 7614 | } |
| 7585 | | 7615 | |
| 7586 | /// Usually, returns null. If an argument was noreturn, returns that ref (which should become the call result). | 7616 | /// Usually, returns null. If an argument was noreturn, returns that ref (which should become the call result). |
| ... | @@ -7597,13 +7627,12 @@ fn analyzeInlineCallArg( | ... | @@ -7597,13 +7627,12 @@ fn analyzeInlineCallArg( |
| 7597 | memoized_arg_values: []InternPool.Index, | 7627 | memoized_arg_values: []InternPool.Index, |
| 7598 | func_ty_info: InternPool.Key.FuncType, | 7628 | func_ty_info: InternPool.Key.FuncType, |
| 7599 | func_inst: Air.Inst.Ref, | 7629 | func_inst: Air.Inst.Ref, |
| 7600 | has_comptime_args: *bool, | | |
| 7601 | ) !?Air.Inst.Ref { | 7630 | ) !?Air.Inst.Ref { |
| 7602 | const mod = ics.sema.mod; | 7631 | const mod = ics.sema.mod; |
| 7603 | const ip = &mod.intern_pool; | 7632 | const ip = &mod.intern_pool; |
| 7604 | const zir_tags = ics.callee().code.instructions.items(.tag); | 7633 | const zir_tags = ics.callee().code.instructions.items(.tag); |
| 7605 | switch (zir_tags[inst]) { | 7634 | switch (zir_tags[inst]) { |
| 7606 | .param_comptime, .param_anytype_comptime => has_comptime_args.* = true, | 7635 | .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true, |
| 7607 | else => {}, | 7636 | else => {}, |
| 7608 | } | 7637 | } |
| 7609 | switch (zir_tags[inst]) { | 7638 | switch (zir_tags[inst]) { |
| ... | @@ -7628,20 +7657,22 @@ fn analyzeInlineCallArg( | ... | @@ -7628,20 +7657,22 @@ fn analyzeInlineCallArg( |
| 7628 | } | 7657 | } |
| 7629 | const arg_src = args_info.argSrc(arg_block, arg_i.*); | 7658 | const arg_src = args_info.argSrc(arg_block, arg_i.*); |
| 7630 | if (try ics.callee().typeRequiresComptime(param_ty.toType())) { | 7659 | 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| { | 7660 | _ = 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); | 7661 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", |
| 7633 | return err; | 7662 | .block_comptime_reason = param_block.comptime_reason, |
| 7634 | }; | 7663 | }); |
| 7635 | } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) { | 7664 | } 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"); | 7665 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| | 7666 | .needed_comptime_reason = "parameter is comptime", |
| | 7667 | }); |
| 7637 | } | 7668 | } |
| 7638 | | 7669 | |
| 7639 | if (is_comptime_call) { | 7670 | if (is_comptime_call) { |
| 7640 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); | 7671 | 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| { | 7672 | 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); | 7673 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7643 | return err; | 7674 | .block_comptime_reason = param_block.comptime_reason, |
| 7644 | }; | 7675 | }); |
| 7645 | switch (arg_val.toIntern()) { | 7676 | switch (arg_val.toIntern()) { |
| 7646 | .generic_poison, .generic_poison_type => { | 7677 | .generic_poison, .generic_poison_type => { |
| 7647 | // This function is currently evaluated as part of an as-of-yet unresolvable | 7678 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -7661,7 +7692,7 @@ fn analyzeInlineCallArg( | ... | @@ -7661,7 +7692,7 @@ fn analyzeInlineCallArg( |
| 7661 | } | 7692 | } |
| 7662 | | 7693 | |
| 7663 | if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| { | 7694 | if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| { |
| 7664 | has_comptime_args.* = true; | 7695 | param_block.inlining.?.has_comptime_args = true; |
| 7665 | } | 7696 | } |
| 7666 | | 7697 | |
| 7667 | arg_i.* += 1; | 7698 | arg_i.* += 1; |
| ... | @@ -7677,10 +7708,10 @@ fn analyzeInlineCallArg( | ... | @@ -7677,10 +7708,10 @@ fn analyzeInlineCallArg( |
| 7677 | | 7708 | |
| 7678 | if (is_comptime_call) { | 7709 | if (is_comptime_call) { |
| 7679 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 7710 | 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| { | 7711 | 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); | 7712 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7682 | return err; | 7713 | .block_comptime_reason = param_block.comptime_reason, |
| 7683 | }; | 7714 | }); |
| 7684 | switch (arg_val.toIntern()) { | 7715 | switch (arg_val.toIntern()) { |
| 7685 | .generic_poison, .generic_poison_type => { | 7716 | .generic_poison, .generic_poison_type => { |
| 7686 | // This function is currently evaluated as part of an as-of-yet unresolvable | 7717 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -7697,13 +7728,15 @@ fn analyzeInlineCallArg( | ... | @@ -7697,13 +7728,15 @@ fn analyzeInlineCallArg( |
| 7697 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); | 7728 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); |
| 7698 | } else { | 7729 | } else { |
| 7699 | if (zir_tags[inst] == .param_anytype_comptime) { | 7730 | if (zir_tags[inst] == .param_anytype_comptime) { |
| 7700 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime"); | 7731 | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{ |
| | 7732 | .needed_comptime_reason = "parameter is comptime", |
| | 7733 | }); |
| 7701 | } | 7734 | } |
| 7702 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 7735 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 7703 | } | 7736 | } |
| 7704 | | 7737 | |
| 7705 | if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| { | 7738 | if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| { |
| 7706 | has_comptime_args.* = true; | 7739 | param_block.inlining.?.has_comptime_args = true; |
| 7707 | } | 7740 | } |
| 7708 | | 7741 | |
| 7709 | arg_i.* += 1; | 7742 | arg_i.* += 1; |
| ... | @@ -7744,7 +7777,9 @@ fn instantiateGenericCall( | ... | @@ -7744,7 +7777,9 @@ fn instantiateGenericCall( |
| 7744 | const gpa = sema.gpa; | 7777 | const gpa = sema.gpa; |
| 7745 | const ip = &mod.intern_pool; | 7778 | const ip = &mod.intern_pool; |
| 7746 | | 7779 | |
| 7747 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); | 7780 | const func_val = try sema.resolveConstValue(block, func_src, func, .{ |
| | 7781 | .needed_comptime_reason = "generic function being called must be comptime-known", |
| | 7782 | }); |
| 7748 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { | 7783 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7749 | .func => func_val.toIntern(), | 7784 | .func => func_val.toIntern(), |
| 7750 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(), | 7785 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(), |
| ... | @@ -7891,7 +7926,7 @@ fn instantiateGenericCall( | ... | @@ -7891,7 +7926,7 @@ fn instantiateGenericCall( |
| 7891 | } else switch (param_tag) { | 7926 | } else switch (param_tag) { |
| 7892 | .param_comptime, | 7927 | .param_comptime, |
| 7893 | .param_anytype_comptime, | 7928 | .param_anytype_comptime, |
| 7894 | => return sema.failWithOwnedErrorMsg(msg: { | 7929 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 7895 | const arg_src = args_info.argSrc(block, arg_index); | 7930 | const arg_src = args_info.argSrc(block, arg_index); |
| 7896 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); | 7931 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); |
| 7897 | errdefer msg.destroy(sema.gpa); | 7932 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -7906,7 +7941,7 @@ fn instantiateGenericCall( | ... | @@ -7906,7 +7941,7 @@ fn instantiateGenericCall( |
| 7906 | | 7941 | |
| 7907 | .param, | 7942 | .param, |
| 7908 | .param_anytype, | 7943 | .param_anytype, |
| 7909 | => return sema.failWithOwnedErrorMsg(msg: { | 7944 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 7910 | const arg_src = args_info.argSrc(block, arg_index); | 7945 | const arg_src = args_info.argSrc(block, arg_index); |
| 7911 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); | 7946 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); |
| 7912 | errdefer msg.destroy(sema.gpa); | 7947 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -8010,7 +8045,7 @@ fn instantiateGenericCall( | ... | @@ -8010,7 +8045,7 @@ fn instantiateGenericCall( |
| 8010 | } | 8045 | } |
| 8011 | if (func_ty.fnReturnType(mod).isNoReturn(mod)) { | 8046 | if (func_ty.fnReturnType(mod).isNoReturn(mod)) { |
| 8012 | _ = try block.addNoOp(.unreach); | 8047 | _ = try block.addNoOp(.unreach); |
| 8013 | return Air.Inst.Ref.unreachable_value; | 8048 | return .unreachable_value; |
| 8014 | } | 8049 | } |
| 8015 | return result; | 8050 | return result; |
| 8016 | } | 8051 | } |
| ... | @@ -8146,7 +8181,9 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8146,7 +8181,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 }; | 8181 | 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 }; | 8182 | 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; | 8183 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8149 | const len = @as(u32, @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known"))); | 8184 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ |
| | 8185 | .needed_comptime_reason = "vector length must be comptime-known", |
| | 8186 | })); |
| 8150 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); | 8187 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); |
| 8151 | try sema.checkVectorElemType(block, elem_type_src, elem_type); | 8188 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 8152 | const vector_type = try mod.vectorType(.{ | 8189 | const vector_type = try mod.vectorType(.{ |
| ... | @@ -8164,7 +8201,9 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8164,7 +8201,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; | 8201 | 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 }; | 8202 | 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 }; | 8203 | 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"); | 8204 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ |
| | 8205 | .needed_comptime_reason = "array length must be comptime-known", |
| | 8206 | }); |
| 8168 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | 8207 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); |
| 8169 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8208 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8170 | const array_ty = try sema.mod.arrayType(.{ | 8209 | const array_ty = try sema.mod.arrayType(.{ |
| ... | @@ -8184,12 +8223,16 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8184,12 +8223,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 }; | 8223 | 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 }; | 8224 | 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 }; | 8225 | 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"); | 8226 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ |
| | 8227 | .needed_comptime_reason = "array length must be comptime-known", |
| | 8228 | }); |
| 8188 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); | 8229 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); |
| 8189 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8230 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8190 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); | 8231 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 8191 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); | 8232 | 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"); | 8233 | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{ |
| | 8234 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 8235 | }); |
| 8193 | const array_ty = try sema.mod.arrayType(.{ | 8236 | const array_ty = try sema.mod.arrayType(.{ |
| 8194 | .len = len, | 8237 | .len = len, |
| 8195 | .sentinel = sentinel_val.toIntern(), | 8238 | .sentinel = sentinel_val.toIntern(), |
| ... | @@ -8347,7 +8390,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8347,7 +8390,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8347 | return block.addInst(.{ | 8390 | return block.addInst(.{ |
| 8348 | .tag = .bitcast, | 8391 | .tag = .bitcast, |
| 8349 | .data = .{ .ty_op = .{ | 8392 | .data = .{ .ty_op = .{ |
| 8350 | .ty = Air.Inst.Ref.anyerror_type, | 8393 | .ty = .anyerror_type, |
| 8351 | .operand = operand, | 8394 | .operand = operand, |
| 8352 | } }, | 8395 | } }, |
| 8353 | }); | 8396 | }); |
| ... | @@ -8373,7 +8416,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8373,7 +8416,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8373 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); | 8416 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 8374 | break :msg msg; | 8417 | break :msg msg; |
| 8375 | }; | 8418 | }; |
| 8376 | return sema.failWithOwnedErrorMsg(msg); | 8419 | return sema.failWithOwnedErrorMsg(block, msg); |
| 8377 | } | 8420 | } |
| 8378 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); | 8421 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 8379 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); | 8422 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| ... | @@ -8384,7 +8427,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8384,7 +8427,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8384 | | 8427 | |
| 8385 | // Anything merged with anyerror is anyerror. | 8428 | // Anything merged with anyerror is anyerror. |
| 8386 | if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) { | 8429 | if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) { |
| 8387 | return Air.Inst.Ref.anyerror_type; | 8430 | return .anyerror_type; |
| 8388 | } | 8431 | } |
| 8389 | | 8432 | |
| 8390 | if (ip.isInferredErrorSetType(lhs_ty.toIntern())) { | 8433 | if (ip.isInferredErrorSetType(lhs_ty.toIntern())) { |
| ... | @@ -8497,7 +8540,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8497,7 +8540,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8497 | try sema.addDeclaredHereNote(msg, dest_ty); | 8540 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 8498 | break :msg msg; | 8541 | break :msg msg; |
| 8499 | }; | 8542 | }; |
| 8500 | return sema.failWithOwnedErrorMsg(msg); | 8543 | return sema.failWithOwnedErrorMsg(block, msg); |
| 8501 | } | 8544 | } |
| 8502 | if (int_val.isUndef(mod)) { | 8545 | if (int_val.isUndef(mod)) { |
| 8503 | return sema.failWithUseOfUndef(block, operand_src); | 8546 | return sema.failWithUseOfUndef(block, operand_src); |
| ... | @@ -8514,7 +8557,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8514,7 +8557,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8514 | try sema.addDeclaredHereNote(msg, dest_ty); | 8557 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 8515 | break :msg msg; | 8558 | break :msg msg; |
| 8516 | }; | 8559 | }; |
| 8517 | return sema.failWithOwnedErrorMsg(msg); | 8560 | return sema.failWithOwnedErrorMsg(block, msg); |
| 8518 | } | 8561 | } |
| 8519 | return Air.internedToRef((try mod.getCoerced(int_val, dest_ty)).toIntern()); | 8562 | return Air.internedToRef((try mod.getCoerced(int_val, dest_ty)).toIntern()); |
| 8520 | } | 8563 | } |
| ... | @@ -8891,7 +8934,7 @@ fn zirFunc( | ... | @@ -8891,7 +8934,7 @@ fn zirFunc( |
| 8891 | const ret_ty: Type = switch (extra.data.ret_body_len) { | 8934 | const ret_ty: Type = switch (extra.data.ret_body_len) { |
| 8892 | 0 => Type.void, | 8935 | 0 => Type.void, |
| 8893 | 1 => blk: { | 8936 | 1 => blk: { |
| 8894 | const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 8937 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 8895 | extra_index += 1; | 8938 | extra_index += 1; |
| 8896 | if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| { | 8939 | if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| { |
| 8897 | break :blk ret_ty; | 8940 | break :blk ret_ty; |
| ... | @@ -8906,7 +8949,9 @@ fn zirFunc( | ... | @@ -8906,7 +8949,9 @@ fn zirFunc( |
| 8906 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; | 8949 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 8907 | extra_index += ret_ty_body.len; | 8950 | extra_index += ret_ty_body.len; |
| 8908 | | 8951 | |
| 8909 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, "return type must be comptime-known"); | 8952 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ |
| | 8953 | .needed_comptime_reason = "return type must be comptime-known", |
| | 8954 | }); |
| 8910 | break :blk ret_ty_val.toType(); | 8955 | break :blk ret_ty_val.toType(); |
| 8911 | }, | 8956 | }, |
| 8912 | }; | 8957 | }; |
| ... | @@ -8953,7 +8998,7 @@ fn resolveGenericBody( | ... | @@ -8953,7 +8998,7 @@ fn resolveGenericBody( |
| 8953 | body: []const Zir.Inst.Index, | 8998 | body: []const Zir.Inst.Index, |
| 8954 | func_inst: Zir.Inst.Index, | 8999 | func_inst: Zir.Inst.Index, |
| 8955 | dest_ty: Type, | 9000 | dest_ty: Type, |
| 8956 | reason: []const u8, | 9001 | reason: NeededComptimeReason, |
| 8957 | ) !Value { | 9002 | ) !Value { |
| 8958 | assert(body.len != 0); | 9003 | assert(body.len != 0); |
| 8959 | | 9004 | |
| ... | @@ -9089,7 +9134,7 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: | ... | @@ -9089,7 +9134,7 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: |
| 9089 | try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); | 9134 | try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); |
| 9090 | break :msg msg; | 9135 | break :msg msg; |
| 9091 | }; | 9136 | }; |
| 9092 | return sema.failWithOwnedErrorMsg(msg); | 9137 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9093 | } | 9138 | } |
| 9094 | } | 9139 | } |
| 9095 | | 9140 | |
| ... | @@ -9185,7 +9230,7 @@ fn funcCommon( | ... | @@ -9185,7 +9230,7 @@ fn funcCommon( |
| 9185 | try sema.addDeclaredHereNote(msg, param_ty); | 9230 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9186 | break :msg msg; | 9231 | break :msg msg; |
| 9187 | }; | 9232 | }; |
| 9188 | return sema.failWithOwnedErrorMsg(msg); | 9233 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9189 | } | 9234 | } |
| 9190 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { | 9235 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { |
| 9191 | const msg = msg: { | 9236 | const msg = msg: { |
| ... | @@ -9200,7 +9245,7 @@ fn funcCommon( | ... | @@ -9200,7 +9245,7 @@ fn funcCommon( |
| 9200 | try sema.addDeclaredHereNote(msg, param_ty); | 9245 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9201 | break :msg msg; | 9246 | break :msg msg; |
| 9202 | }; | 9247 | }; |
| 9203 | return sema.failWithOwnedErrorMsg(msg); | 9248 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9204 | } | 9249 | } |
| 9205 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body) { | 9250 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body) { |
| 9206 | const msg = msg: { | 9251 | const msg = msg: { |
| ... | @@ -9215,7 +9260,7 @@ fn funcCommon( | ... | @@ -9215,7 +9260,7 @@ fn funcCommon( |
| 9215 | try sema.addDeclaredHereNote(msg, param_ty); | 9260 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9216 | break :msg msg; | 9261 | break :msg msg; |
| 9217 | }; | 9262 | }; |
| 9218 | return sema.failWithOwnedErrorMsg(msg); | 9263 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9219 | } | 9264 | } |
| 9220 | if (is_source_decl and !this_generic and is_noalias and | 9265 | if (is_source_decl and !this_generic and is_noalias and |
| 9221 | !(param_ty.zigTypeTag(mod) == .Pointer or param_ty.isPtrLikeOptional(mod))) | 9266 | !(param_ty.zigTypeTag(mod) == .Pointer or param_ty.isPtrLikeOptional(mod))) |
| ... | @@ -9477,7 +9522,7 @@ fn finishFunc( | ... | @@ -9477,7 +9522,7 @@ fn finishFunc( |
| 9477 | try sema.addDeclaredHereNote(msg, return_type); | 9522 | try sema.addDeclaredHereNote(msg, return_type); |
| 9478 | break :msg msg; | 9523 | break :msg msg; |
| 9479 | }; | 9524 | }; |
| 9480 | return sema.failWithOwnedErrorMsg(msg); | 9525 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9481 | } | 9526 | } |
| 9482 | if (!ret_poison and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and | 9527 | if (!ret_poison and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and |
| 9483 | !try sema.validateExternType(return_type, .ret_ty)) | 9528 | !try sema.validateExternType(return_type, .ret_ty)) |
| ... | @@ -9494,7 +9539,7 @@ fn finishFunc( | ... | @@ -9494,7 +9539,7 @@ fn finishFunc( |
| 9494 | try sema.addDeclaredHereNote(msg, return_type); | 9539 | try sema.addDeclaredHereNote(msg, return_type); |
| 9495 | break :msg msg; | 9540 | break :msg msg; |
| 9496 | }; | 9541 | }; |
| 9497 | return sema.failWithOwnedErrorMsg(msg); | 9542 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9498 | } | 9543 | } |
| 9499 | | 9544 | |
| 9500 | // If the return type is comptime-only but not dependent on parameters then | 9545 | // If the return type is comptime-only but not dependent on parameters then |
| ... | @@ -9534,41 +9579,41 @@ fn finishFunc( | ... | @@ -9534,41 +9579,41 @@ fn finishFunc( |
| 9534 | } | 9579 | } |
| 9535 | } | 9580 | } |
| 9536 | } | 9581 | } |
| 9537 | return sema.failWithOwnedErrorMsg(msg); | 9582 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9538 | } | 9583 | } |
| 9539 | | 9584 | |
| 9540 | const arch = target.cpu.arch; | 9585 | const arch = target.cpu.arch; |
| 9541 | if (switch (cc_resolved) { | 9586 | if (@as(?[]const u8, switch (cc_resolved) { |
| 9542 | .Unspecified, .C, .Naked, .Async, .Inline => null, | 9587 | .Unspecified, .C, .Naked, .Async, .Inline => null, |
| 9543 | .Interrupt => switch (arch) { | 9588 | .Interrupt => switch (arch) { |
| 9544 | .x86, .x86_64, .avr, .msp430 => null, | 9589 | .x86, .x86_64, .avr, .msp430 => null, |
| 9545 | else => @as([]const u8, "x86, x86_64, AVR, and MSP430"), | 9590 | else => "x86, x86_64, AVR, and MSP430", |
| 9546 | }, | 9591 | }, |
| 9547 | .Signal => switch (arch) { | 9592 | .Signal => switch (arch) { |
| 9548 | .avr => null, | 9593 | .avr => null, |
| 9549 | else => @as([]const u8, "AVR"), | 9594 | else => "AVR", |
| 9550 | }, | 9595 | }, |
| 9551 | .Stdcall, .Fastcall, .Thiscall => switch (arch) { | 9596 | .Stdcall, .Fastcall, .Thiscall => switch (arch) { |
| 9552 | .x86 => null, | 9597 | .x86 => null, |
| 9553 | else => @as([]const u8, "x86"), | 9598 | else => "x86", |
| 9554 | }, | 9599 | }, |
| 9555 | .Vectorcall => switch (arch) { | 9600 | .Vectorcall => switch (arch) { |
| 9556 | .x86, .aarch64, .aarch64_be, .aarch64_32 => null, | 9601 | .x86, .aarch64, .aarch64_be, .aarch64_32 => null, |
| 9557 | else => @as([]const u8, "x86 and AArch64"), | 9602 | else => "x86 and AArch64", |
| 9558 | }, | 9603 | }, |
| 9559 | .APCS, .AAPCS, .AAPCSVFP => switch (arch) { | 9604 | .APCS, .AAPCS, .AAPCSVFP => switch (arch) { |
| 9560 | .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32, .thumb, .thumbeb => null, | 9605 | .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32, .thumb, .thumbeb => null, |
| 9561 | else => @as([]const u8, "ARM"), | 9606 | else => "ARM", |
| 9562 | }, | 9607 | }, |
| 9563 | .SysV, .Win64 => switch (arch) { | 9608 | .SysV, .Win64 => switch (arch) { |
| 9564 | .x86_64 => null, | 9609 | .x86_64 => null, |
| 9565 | else => @as([]const u8, "x86_64"), | 9610 | else => "x86_64", |
| 9566 | }, | 9611 | }, |
| 9567 | .Kernel => switch (arch) { | 9612 | .Kernel => switch (arch) { |
| 9568 | .nvptx, .nvptx64, .amdgcn, .spirv32, .spirv64 => null, | 9613 | .nvptx, .nvptx64, .amdgcn, .spirv32, .spirv64 => null, |
| 9569 | else => @as([]const u8, "nvptx, amdgcn and SPIR-V"), | 9614 | else => "nvptx, amdgcn and SPIR-V", |
| 9570 | }, | 9615 | }, |
| 9571 | }) |allowed_platform| { | 9616 | })) |allowed_platform| { |
| 9572 | return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{ | 9617 | return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{ |
| 9573 | @tagName(cc_resolved), | 9618 | @tagName(cc_resolved), |
| 9574 | allowed_platform, | 9619 | allowed_platform, |
| ... | @@ -9852,7 +9897,9 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -9852,7 +9897,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 }; | 9897 | 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; | 9898 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9854 | const object = try sema.resolveInst(extra.lhs); | 9899 | 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"); | 9900 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| | 9901 | .needed_comptime_reason = "field name must be comptime-known", |
| | 9902 | }); |
| 9856 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 9903 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 9857 | } | 9904 | } |
| 9858 | | 9905 | |
| ... | @@ -9865,7 +9912,9 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -9865,7 +9912,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 }; | 9912 | 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; | 9913 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9867 | const object_ptr = try sema.resolveInst(extra.lhs); | 9914 | 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"); | 9915 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| | 9916 | .needed_comptime_reason = "field name must be comptime-known", |
| | 9917 | }); |
| 9869 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); | 9918 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 9870 | } | 9919 | } |
| 9871 | | 9920 | |
| ... | @@ -10071,7 +10120,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10071,7 +10120,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10071 | | 10120 | |
| 10072 | break :msg msg; | 10121 | break :msg msg; |
| 10073 | }; | 10122 | }; |
| 10074 | return sema.failWithOwnedErrorMsg(msg); | 10123 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10075 | }, | 10124 | }, |
| 10076 | | 10125 | |
| 10077 | .Pointer => { | 10126 | .Pointer => { |
| ... | @@ -10086,7 +10135,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10086,7 +10135,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10086 | | 10135 | |
| 10087 | break :msg msg; | 10136 | break :msg msg; |
| 10088 | }; | 10137 | }; |
| 10089 | return sema.failWithOwnedErrorMsg(msg); | 10138 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10090 | }, | 10139 | }, |
| 10091 | .Struct, .Union => if (dest_ty.containerLayout(mod) == .Auto) { | 10140 | .Struct, .Union => if (dest_ty.containerLayout(mod) == .Auto) { |
| 10092 | const container = switch (dest_ty.zigTypeTag(mod)) { | 10141 | const container = switch (dest_ty.zigTypeTag(mod)) { |
| ... | @@ -10135,7 +10184,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10135,7 +10184,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10135 | | 10184 | |
| 10136 | break :msg msg; | 10185 | break :msg msg; |
| 10137 | }; | 10186 | }; |
| 10138 | return sema.failWithOwnedErrorMsg(msg); | 10187 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10139 | }, | 10188 | }, |
| 10140 | .Pointer => { | 10189 | .Pointer => { |
| 10141 | const msg = msg: { | 10190 | const msg = msg: { |
| ... | @@ -10149,7 +10198,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10149,7 +10198,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10149 | | 10198 | |
| 10150 | break :msg msg; | 10199 | break :msg msg; |
| 10151 | }; | 10200 | }; |
| 10152 | return sema.failWithOwnedErrorMsg(msg); | 10201 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10153 | }, | 10202 | }, |
| 10154 | .Struct, .Union => if (operand_ty.containerLayout(mod) == .Auto) { | 10203 | .Struct, .Union => if (operand_ty.containerLayout(mod) == .Auto) { |
| 10155 | const container = switch (operand_ty.zigTypeTag(mod)) { | 10204 | const container = switch (operand_ty.zigTypeTag(mod)) { |
| ... | @@ -10300,7 +10349,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10300,7 +10349,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10300 | } | 10349 | } |
| 10301 | break :msg msg; | 10350 | break :msg msg; |
| 10302 | }; | 10351 | }; |
| 10303 | return sema.failWithOwnedErrorMsg(msg); | 10352 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10304 | } | 10353 | } |
| 10305 | return sema.elemPtrOneLayerOnly(block, src, array_ptr, elem_index, src, false, false); | 10354 | return sema.elemPtrOneLayerOnly(block, src, array_ptr, elem_index, src, false, false); |
| 10306 | } | 10355 | } |
| ... | @@ -10472,7 +10521,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10472,7 +10521,7 @@ const SwitchProngAnalysis = struct { |
| 10472 | | 10521 | |
| 10473 | if (sema.typeOf(capture_ref).isNoReturn(sema.mod)) { | 10522 | if (sema.typeOf(capture_ref).isNoReturn(sema.mod)) { |
| 10474 | // This prong should be unreachable! | 10523 | // This prong should be unreachable! |
| 10475 | return Air.Inst.Ref.unreachable_value; | 10524 | return .unreachable_value; |
| 10476 | } | 10525 | } |
| 10477 | | 10526 | |
| 10478 | sema.inst_map.putAssumeCapacity(spa.switch_block_inst, capture_ref); | 10527 | sema.inst_map.putAssumeCapacity(spa.switch_block_inst, capture_ref); |
| ... | @@ -10566,7 +10615,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10566,7 +10615,7 @@ const SwitchProngAnalysis = struct { |
| 10566 | try sema.addDeclaredHereNote(msg, operand_ty); | 10615 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 10567 | break :msg msg; | 10616 | break :msg msg; |
| 10568 | }; | 10617 | }; |
| 10569 | return sema.failWithOwnedErrorMsg(msg); | 10618 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10570 | } | 10619 | } |
| 10571 | assert(inline_case_capture != .none); | 10620 | assert(inline_case_capture != .none); |
| 10572 | return inline_case_capture; | 10621 | return inline_case_capture; |
| ... | @@ -10593,7 +10642,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10593,7 +10642,7 @@ const SwitchProngAnalysis = struct { |
| 10593 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; | 10642 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; |
| 10594 | | 10643 | |
| 10595 | if (inline_case_capture != .none) { | 10644 | if (inline_case_capture != .none) { |
| 10596 | const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable; | 10645 | const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; |
| 10597 | if (operand_ty.zigTypeTag(mod) == .Union) { | 10646 | if (operand_ty.zigTypeTag(mod) == .Union) { |
| 10598 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?); | 10647 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?); |
| 10599 | const union_obj = mod.typeToUnion(operand_ty).?; | 10648 | const union_obj = mod.typeToUnion(operand_ty).?; |
| ... | @@ -10641,7 +10690,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10641,7 +10690,7 @@ const SwitchProngAnalysis = struct { |
| 10641 | return sema.bitCast(block, ty, spa.operand, operand_src, null); | 10690 | return sema.bitCast(block, ty, spa.operand, operand_src, null); |
| 10642 | } else { | 10691 | } else { |
| 10643 | try block.addUnreachable(operand_src, false); | 10692 | try block.addUnreachable(operand_src, false); |
| 10644 | return Air.Inst.Ref.unreachable_value; | 10693 | return .unreachable_value; |
| 10645 | }, | 10694 | }, |
| 10646 | else => return spa.operand, | 10695 | else => return spa.operand, |
| 10647 | } | 10696 | } |
| ... | @@ -10650,14 +10699,14 @@ const SwitchProngAnalysis = struct { | ... | @@ -10650,14 +10699,14 @@ const SwitchProngAnalysis = struct { |
| 10650 | switch (operand_ty.zigTypeTag(mod)) { | 10699 | switch (operand_ty.zigTypeTag(mod)) { |
| 10651 | .Union => { | 10700 | .Union => { |
| 10652 | const union_obj = mod.typeToUnion(operand_ty).?; | 10701 | const union_obj = mod.typeToUnion(operand_ty).?; |
| 10653 | const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable; | 10702 | const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 10654 | | 10703 | |
| 10655 | const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?; | 10704 | 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(); | 10705 | const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType(); |
| 10657 | | 10706 | |
| 10658 | const field_tys = try sema.arena.alloc(Type, case_vals.len); | 10707 | const field_tys = try sema.arena.alloc(Type, case_vals.len); |
| 10659 | for (case_vals, field_tys) |item, *field_ty| { | 10708 | for (case_vals, field_tys) |item, *field_ty| { |
| 10660 | const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable; | 10709 | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 10661 | const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?; | 10710 | const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?; |
| 10662 | field_ty.* = union_obj.field_types.get(ip)[field_idx].toType(); | 10711 | field_ty.* = union_obj.field_types.get(ip)[field_idx].toType(); |
| 10663 | } | 10712 | } |
| ... | @@ -10684,7 +10733,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10684,7 +10733,7 @@ const SwitchProngAnalysis = struct { |
| 10684 | const multi_idx = raw_capture_src.multi_capture; | 10733 | const multi_idx = raw_capture_src.multi_capture; |
| 10685 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); | 10734 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); |
| 10686 | for (case_srcs, 0..) |*case_src, i| { | 10735 | for (case_srcs, 0..) |*case_src, i| { |
| 10687 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } }; | 10736 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 10688 | case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); | 10737 | case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10689 | } | 10738 | } |
| 10690 | const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); | 10739 | const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| ... | @@ -10732,7 +10781,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10732,7 +10781,7 @@ const SwitchProngAnalysis = struct { |
| 10732 | const multi_idx = raw_capture_src.multi_capture; | 10781 | const multi_idx = raw_capture_src.multi_capture; |
| 10733 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); | 10782 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); |
| 10734 | const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); | 10783 | const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10735 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } }; | 10784 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 10736 | const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); | 10785 | const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10737 | const msg = msg: { | 10786 | const msg = msg: { |
| 10738 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); | 10787 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); |
| ... | @@ -10744,7 +10793,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10744,7 +10793,7 @@ const SwitchProngAnalysis = struct { |
| 10744 | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); | 10793 | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 10745 | break :msg msg; | 10794 | break :msg msg; |
| 10746 | }; | 10795 | }; |
| 10747 | return sema.failWithOwnedErrorMsg(msg); | 10796 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10748 | } | 10797 | } |
| 10749 | } | 10798 | } |
| 10750 | } | 10799 | } |
| ... | @@ -10833,12 +10882,12 @@ const SwitchProngAnalysis = struct { | ... | @@ -10833,12 +10882,12 @@ const SwitchProngAnalysis = struct { |
| 10833 | var coerce_block = block.makeSubBlock(); | 10882 | var coerce_block = block.makeSubBlock(); |
| 10834 | defer coerce_block.instructions.deinit(sema.gpa); | 10883 | defer coerce_block.instructions.deinit(sema.gpa); |
| 10835 | | 10884 | |
| 10836 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(idx)), field_tys[idx]); | 10885 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(idx), field_tys[idx]); |
| 10837 | const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) { | 10886 | const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) { |
| 10838 | error.NeededSourceLocation => { | 10887 | error.NeededSourceLocation => { |
| 10839 | const multi_idx = raw_capture_src.multi_capture; | 10888 | const multi_idx = raw_capture_src.multi_capture; |
| 10840 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); | 10889 | const src_decl_ptr = sema.mod.declPtr(block.src_decl); |
| 10841 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(idx)) } }; | 10890 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } }; |
| 10842 | const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); | 10891 | const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none); |
| 10843 | _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); | 10892 | _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); |
| 10844 | unreachable; | 10893 | unreachable; |
| ... | @@ -10849,7 +10898,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10849,7 +10898,7 @@ const SwitchProngAnalysis = struct { |
| 10849 | | 10898 | |
| 10850 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); | 10899 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); |
| 10851 | cases_extra.appendAssumeCapacity(1); // items_len | 10900 | cases_extra.appendAssumeCapacity(1); // items_len |
| 10852 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(coerce_block.instructions.items.len))); // body_len | 10901 | cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len |
| 10853 | cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item | 10902 | cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item |
| 10854 | cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body | 10903 | cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body |
| 10855 | } | 10904 | } |
| ... | @@ -10860,7 +10909,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10860,7 +10909,7 @@ const SwitchProngAnalysis = struct { |
| 10860 | defer coerce_block.instructions.deinit(sema.gpa); | 10909 | defer coerce_block.instructions.deinit(sema.gpa); |
| 10861 | | 10910 | |
| 10862 | const first_imc = in_mem_coercible.findFirstSet().?; | 10911 | const first_imc = in_mem_coercible.findFirstSet().?; |
| 10863 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(first_imc)), field_tys[first_imc]); | 10912 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(first_imc), field_tys[first_imc]); |
| 10864 | const coerced = try coerce_block.addBitCast(capture_ty, uncoerced); | 10913 | const coerced = try coerce_block.addBitCast(capture_ty, uncoerced); |
| 10865 | _ = try coerce_block.addBr(capture_block_inst, coerced); | 10914 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 10866 | | 10915 | |
| ... | @@ -10873,14 +10922,14 @@ const SwitchProngAnalysis = struct { | ... | @@ -10873,14 +10922,14 @@ const SwitchProngAnalysis = struct { |
| 10873 | @typeInfo(Air.Block).Struct.fields.len + | 10922 | @typeInfo(Air.Block).Struct.fields.len + |
| 10874 | 1); | 10923 | 1); |
| 10875 | | 10924 | |
| 10876 | const switch_br_inst = @as(u32, @intCast(sema.air_instructions.len)); | 10925 | const switch_br_inst: u32 = @intCast(sema.air_instructions.len); |
| 10877 | try sema.air_instructions.append(sema.gpa, .{ | 10926 | try sema.air_instructions.append(sema.gpa, .{ |
| 10878 | .tag = .switch_br, | 10927 | .tag = .switch_br, |
| 10879 | .data = .{ .pl_op = .{ | 10928 | .data = .{ .pl_op = .{ |
| 10880 | .operand = spa.cond, | 10929 | .operand = spa.cond, |
| 10881 | .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{ | 10930 | .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{ |
| 10882 | .cases_len = @as(u32, @intCast(prong_count)), | 10931 | .cases_len = @intCast(prong_count), |
| 10883 | .else_body_len = @as(u32, @intCast(else_body_len)), | 10932 | .else_body_len = @intCast(else_body_len), |
| 10884 | }), | 10933 | }), |
| 10885 | } }, | 10934 | } }, |
| 10886 | }); | 10935 | }); |
| ... | @@ -10906,7 +10955,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10906,7 +10955,7 @@ const SwitchProngAnalysis = struct { |
| 10906 | } | 10955 | } |
| 10907 | | 10956 | |
| 10908 | if (case_vals.len == 1) { | 10957 | if (case_vals.len == 1) { |
| 10909 | const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable; | 10958 | 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().?); | 10959 | const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?); |
| 10911 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); | 10960 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 10912 | } | 10961 | } |
| ... | @@ -10914,7 +10963,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -10914,7 +10963,7 @@ const SwitchProngAnalysis = struct { |
| 10914 | var names: InferredErrorSet.NameMap = .{}; | 10963 | var names: InferredErrorSet.NameMap = .{}; |
| 10915 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); | 10964 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 10916 | for (case_vals) |err| { | 10965 | for (case_vals) |err| { |
| 10917 | const err_val = sema.resolveConstValue(block, .unneeded, err, "") catch unreachable; | 10966 | const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable; |
| 10918 | names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {}); | 10967 | names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {}); |
| 10919 | } | 10968 | } |
| 10920 | const error_ty = try mod.errorSetFromUnsortedNames(names.keys()); | 10969 | const error_ty = try mod.errorSetFromUnsortedNames(names.keys()); |
| ... | @@ -10975,7 +11024,7 @@ fn switchCond( | ... | @@ -10975,7 +11024,7 @@ fn switchCond( |
| 10975 | } | 11024 | } |
| 10976 | break :msg msg; | 11025 | break :msg msg; |
| 10977 | }; | 11026 | }; |
| 10978 | return sema.failWithOwnedErrorMsg(msg); | 11027 | return sema.failWithOwnedErrorMsg(block, msg); |
| 10979 | }; | 11028 | }; |
| 10980 | return sema.unionToTag(block, enum_ty, operand, src); | 11029 | return sema.unionToTag(block, enum_ty, operand, src); |
| 10981 | }, | 11030 | }, |
| ... | @@ -11067,7 +11116,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11067,7 +11116,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11067 | .has_tag_capture = false, | 11116 | .has_tag_capture = false, |
| 11068 | }, | 11117 | }, |
| 11069 | .under, .@"else" => blk: { | 11118 | .under, .@"else" => blk: { |
| 11070 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[header_extra_index])); | 11119 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]); |
| 11071 | const extra_body_start = header_extra_index + 1; | 11120 | const extra_body_start = header_extra_index + 1; |
| 11072 | break :blk .{ | 11121 | break :blk .{ |
| 11073 | .body = sema.code.extra[extra_body_start..][0..info.body_len], | 11122 | .body = sema.code.extra[extra_body_start..][0..info.body_len], |
| ... | @@ -11128,7 +11177,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11128,7 +11177,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11128 | ); | 11177 | ); |
| 11129 | break :msg msg; | 11178 | break :msg msg; |
| 11130 | }; | 11179 | }; |
| 11131 | return sema.failWithOwnedErrorMsg(msg); | 11180 | return sema.failWithOwnedErrorMsg(block, msg); |
| 11132 | } | 11181 | } |
| 11133 | | 11182 | |
| 11134 | // Validate for duplicate items, missing else prong, and invalid range. | 11183 | // Validate for duplicate items, missing else prong, and invalid range. |
| ... | @@ -11144,9 +11193,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11144,9 +11193,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11144 | { | 11193 | { |
| 11145 | var scalar_i: u32 = 0; | 11194 | var scalar_i: u32 = 0; |
| 11146 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11195 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11147 | const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11196 | const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11148 | extra_index += 1; | 11197 | extra_index += 1; |
| 11149 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11198 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11150 | extra_index += 1 + info.body_len; | 11199 | extra_index += 1 + info.body_len; |
| 11151 | | 11200 | |
| 11152 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum( | 11201 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum( |
| ... | @@ -11167,7 +11216,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11167,7 +11216,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11167 | extra_index += 1; | 11216 | extra_index += 1; |
| 11168 | const ranges_len = sema.code.extra[extra_index]; | 11217 | const ranges_len = sema.code.extra[extra_index]; |
| 11169 | extra_index += 1; | 11218 | extra_index += 1; |
| 11170 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11219 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11171 | extra_index += 1; | 11220 | extra_index += 1; |
| 11172 | const items = sema.code.refSlice(extra_index, items_len); | 11221 | const items = sema.code.refSlice(extra_index, items_len); |
| 11173 | extra_index += items_len + info.body_len; | 11222 | extra_index += items_len + info.body_len; |
| ... | @@ -11181,7 +11230,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11181,7 +11230,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11181 | item_ref, | 11230 | item_ref, |
| 11182 | operand_ty, | 11231 | operand_ty, |
| 11183 | src_node_offset, | 11232 | src_node_offset, |
| 11184 | .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }, | 11233 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11185 | )); | 11234 | )); |
| 11186 | } | 11235 | } |
| 11187 | | 11236 | |
| ... | @@ -11228,7 +11277,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11228,7 +11277,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11228 | ); | 11277 | ); |
| 11229 | break :msg msg; | 11278 | break :msg msg; |
| 11230 | }; | 11279 | }; |
| 11231 | return sema.failWithOwnedErrorMsg(msg); | 11280 | return sema.failWithOwnedErrorMsg(block, msg); |
| 11232 | } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum(mod) and !union_originally) { | 11281 | } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum(mod) and !union_originally) { |
| 11233 | return sema.fail( | 11282 | return sema.fail( |
| 11234 | block, | 11283 | block, |
| ... | @@ -11243,9 +11292,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11243,9 +11292,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11243 | { | 11292 | { |
| 11244 | var scalar_i: u32 = 0; | 11293 | var scalar_i: u32 = 0; |
| 11245 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11294 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11246 | const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11295 | const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11247 | extra_index += 1; | 11296 | extra_index += 1; |
| 11248 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11297 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11249 | extra_index += 1 + info.body_len; | 11298 | extra_index += 1 + info.body_len; |
| 11250 | | 11299 | |
| 11251 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemError( | 11300 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemError( |
| ... | @@ -11265,7 +11314,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11265,7 +11314,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11265 | extra_index += 1; | 11314 | extra_index += 1; |
| 11266 | const ranges_len = sema.code.extra[extra_index]; | 11315 | const ranges_len = sema.code.extra[extra_index]; |
| 11267 | extra_index += 1; | 11316 | extra_index += 1; |
| 11268 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11317 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11269 | extra_index += 1; | 11318 | extra_index += 1; |
| 11270 | const items = sema.code.refSlice(extra_index, items_len); | 11319 | const items = sema.code.refSlice(extra_index, items_len); |
| 11271 | extra_index += items_len + info.body_len; | 11320 | extra_index += items_len + info.body_len; |
| ... | @@ -11278,7 +11327,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11278,7 +11327,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11278 | item_ref, | 11327 | item_ref, |
| 11279 | operand_ty, | 11328 | operand_ty, |
| 11280 | src_node_offset, | 11329 | src_node_offset, |
| 11281 | .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }, | 11330 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11282 | )); | 11331 | )); |
| 11283 | } | 11332 | } |
| 11284 | | 11333 | |
| ... | @@ -11328,7 +11377,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11328,7 +11377,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11328 | if (maybe_msg) |msg| { | 11377 | if (maybe_msg) |msg| { |
| 11329 | maybe_msg = null; | 11378 | maybe_msg = null; |
| 11330 | try sema.addDeclaredHereNote(msg, operand_ty); | 11379 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 11331 | return sema.failWithOwnedErrorMsg(msg); | 11380 | return sema.failWithOwnedErrorMsg(block, msg); |
| 11332 | } | 11381 | } |
| 11333 | | 11382 | |
| 11334 | if (special_prong == .@"else" and | 11383 | if (special_prong == .@"else" and |
| ... | @@ -11387,9 +11436,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11387,9 +11436,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11387 | { | 11436 | { |
| 11388 | var scalar_i: u32 = 0; | 11437 | var scalar_i: u32 = 0; |
| 11389 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11438 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11390 | const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11439 | const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11391 | extra_index += 1; | 11440 | extra_index += 1; |
| 11392 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11441 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11393 | extra_index += 1 + info.body_len; | 11442 | extra_index += 1 + info.body_len; |
| 11394 | | 11443 | |
| 11395 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt( | 11444 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt( |
| ... | @@ -11409,7 +11458,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11409,7 +11458,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11409 | extra_index += 1; | 11458 | extra_index += 1; |
| 11410 | const ranges_len = sema.code.extra[extra_index]; | 11459 | const ranges_len = sema.code.extra[extra_index]; |
| 11411 | extra_index += 1; | 11460 | extra_index += 1; |
| 11412 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11461 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11413 | extra_index += 1; | 11462 | extra_index += 1; |
| 11414 | const items = sema.code.refSlice(extra_index, items_len); | 11463 | const items = sema.code.refSlice(extra_index, items_len); |
| 11415 | extra_index += items_len; | 11464 | extra_index += items_len; |
| ... | @@ -11422,16 +11471,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11422,16 +11471,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11422 | item_ref, | 11471 | item_ref, |
| 11423 | operand_ty, | 11472 | operand_ty, |
| 11424 | src_node_offset, | 11473 | src_node_offset, |
| 11425 | .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }, | 11474 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11426 | )); | 11475 | )); |
| 11427 | } | 11476 | } |
| 11428 | | 11477 | |
| 11429 | try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len); | 11478 | try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len); |
| 11430 | var range_i: u32 = 0; | 11479 | var range_i: u32 = 0; |
| 11431 | while (range_i < ranges_len) : (range_i += 1) { | 11480 | while (range_i < ranges_len) : (range_i += 1) { |
| 11432 | const item_first = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11481 | const item_first: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11433 | extra_index += 1; | 11482 | extra_index += 1; |
| 11434 | const item_last = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11483 | const item_last: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11435 | extra_index += 1; | 11484 | extra_index += 1; |
| 11436 | | 11485 | |
| 11437 | const vals = try sema.validateSwitchRange( | 11486 | const vals = try sema.validateSwitchRange( |
| ... | @@ -11482,9 +11531,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11482,9 +11531,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11482 | { | 11531 | { |
| 11483 | var scalar_i: u32 = 0; | 11532 | var scalar_i: u32 = 0; |
| 11484 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11533 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11485 | const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11534 | const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11486 | extra_index += 1; | 11535 | extra_index += 1; |
| 11487 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11536 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11488 | extra_index += 1 + info.body_len; | 11537 | extra_index += 1 + info.body_len; |
| 11489 | | 11538 | |
| 11490 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool( | 11539 | case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool( |
| ... | @@ -11504,7 +11553,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11504,7 +11553,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11504 | extra_index += 1; | 11553 | extra_index += 1; |
| 11505 | const ranges_len = sema.code.extra[extra_index]; | 11554 | const ranges_len = sema.code.extra[extra_index]; |
| 11506 | extra_index += 1; | 11555 | extra_index += 1; |
| 11507 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11556 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11508 | extra_index += 1; | 11557 | extra_index += 1; |
| 11509 | const items = sema.code.refSlice(extra_index, items_len); | 11558 | const items = sema.code.refSlice(extra_index, items_len); |
| 11510 | extra_index += items_len + info.body_len; | 11559 | extra_index += items_len + info.body_len; |
| ... | @@ -11517,7 +11566,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11517,7 +11566,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11517 | &false_count, | 11566 | &false_count, |
| 11518 | item_ref, | 11567 | item_ref, |
| 11519 | src_node_offset, | 11568 | src_node_offset, |
| 11520 | .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }, | 11569 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11521 | )); | 11570 | )); |
| 11522 | } | 11571 | } |
| 11523 | | 11572 | |
| ... | @@ -11564,9 +11613,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11564,9 +11613,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11564 | { | 11613 | { |
| 11565 | var scalar_i: u32 = 0; | 11614 | var scalar_i: u32 = 0; |
| 11566 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11615 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11567 | const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 11616 | const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 11568 | extra_index += 1; | 11617 | extra_index += 1; |
| 11569 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11618 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11570 | extra_index += 1; | 11619 | extra_index += 1; |
| 11571 | extra_index += info.body_len; | 11620 | extra_index += info.body_len; |
| 11572 | | 11621 | |
| ... | @@ -11587,7 +11636,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11587,7 +11636,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11587 | extra_index += 1; | 11636 | extra_index += 1; |
| 11588 | const ranges_len = sema.code.extra[extra_index]; | 11637 | const ranges_len = sema.code.extra[extra_index]; |
| 11589 | extra_index += 1; | 11638 | extra_index += 1; |
| 11590 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11639 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11591 | extra_index += 1; | 11640 | extra_index += 1; |
| 11592 | const items = sema.code.refSlice(extra_index, items_len); | 11641 | const items = sema.code.refSlice(extra_index, items_len); |
| 11593 | extra_index += items_len + info.body_len; | 11642 | extra_index += items_len + info.body_len; |
| ... | @@ -11600,7 +11649,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11600,7 +11649,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11600 | item_ref, | 11649 | item_ref, |
| 11601 | operand_ty, | 11650 | operand_ty, |
| 11602 | src_node_offset, | 11651 | src_node_offset, |
| 11603 | .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }, | 11652 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11604 | )); | 11653 | )); |
| 11605 | } | 11654 | } |
| 11606 | | 11655 | |
| ... | @@ -11638,7 +11687,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11638,7 +11687,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11638 | .tag_capture_inst = tag_capture_inst, | 11687 | .tag_capture_inst = tag_capture_inst, |
| 11639 | }; | 11688 | }; |
| 11640 | | 11689 | |
| 11641 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 11690 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 11642 | try sema.air_instructions.append(gpa, .{ | 11691 | try sema.air_instructions.append(gpa, .{ |
| 11643 | .tag = .block, | 11692 | .tag = .block, |
| 11644 | .data = undefined, | 11693 | .data = undefined, |
| ... | @@ -11682,13 +11731,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11682,13 +11731,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11682 | var scalar_i: usize = 0; | 11731 | var scalar_i: usize = 0; |
| 11683 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11732 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11684 | extra_index += 1; | 11733 | extra_index += 1; |
| 11685 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11734 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11686 | extra_index += 1; | 11735 | extra_index += 1; |
| 11687 | const body = sema.code.extra[extra_index..][0..info.body_len]; | 11736 | const body = sema.code.extra[extra_index..][0..info.body_len]; |
| 11688 | extra_index += info.body_len; | 11737 | extra_index += info.body_len; |
| 11689 | | 11738 | |
| 11690 | const item = case_vals.items[scalar_i]; | 11739 | const item = case_vals.items[scalar_i]; |
| 11691 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable; | 11740 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11692 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 11741 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11693 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); | 11742 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11694 | return spa.resolveProngComptime( | 11743 | return spa.resolveProngComptime( |
| ... | @@ -11696,7 +11745,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11696,7 +11745,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11696 | .normal, | 11745 | .normal, |
| 11697 | body, | 11746 | body, |
| 11698 | info.capture, | 11747 | info.capture, |
| 11699 | .{ .scalar_capture = @as(u32, @intCast(scalar_i)) }, | 11748 | .{ .scalar_capture = @intCast(scalar_i) }, |
| 11700 | &.{item}, | 11749 | &.{item}, |
| 11701 | if (info.is_inline) operand else .none, | 11750 | if (info.is_inline) operand else .none, |
| 11702 | info.has_tag_capture, | 11751 | info.has_tag_capture, |
| ... | @@ -11713,7 +11762,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11713,7 +11762,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11713 | extra_index += 1; | 11762 | extra_index += 1; |
| 11714 | const ranges_len = sema.code.extra[extra_index]; | 11763 | const ranges_len = sema.code.extra[extra_index]; |
| 11715 | extra_index += 1; | 11764 | extra_index += 1; |
| 11716 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11765 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11717 | extra_index += 1 + items_len; | 11766 | extra_index += 1 + items_len; |
| 11718 | const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len]; | 11767 | const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len]; |
| 11719 | | 11768 | |
| ... | @@ -11722,7 +11771,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11722,7 +11771,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11722 | | 11771 | |
| 11723 | for (items) |item| { | 11772 | for (items) |item| { |
| 11724 | // Validation above ensured these will succeed. | 11773 | // Validation above ensured these will succeed. |
| 11725 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable; | 11774 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11726 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 11775 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11727 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); | 11776 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11728 | return spa.resolveProngComptime( | 11777 | return spa.resolveProngComptime( |
| ... | @@ -11730,7 +11779,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11730,7 +11779,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11730 | .normal, | 11779 | .normal, |
| 11731 | body, | 11780 | body, |
| 11732 | info.capture, | 11781 | info.capture, |
| 11733 | .{ .multi_capture = @as(u32, @intCast(multi_i)) }, | 11782 | .{ .multi_capture = @intCast(multi_i) }, |
| 11734 | items, | 11783 | items, |
| 11735 | if (info.is_inline) operand else .none, | 11784 | if (info.is_inline) operand else .none, |
| 11736 | info.has_tag_capture, | 11785 | info.has_tag_capture, |
| ... | @@ -11746,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11746,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11746 | case_val_idx += 2; | 11795 | case_val_idx += 2; |
| 11747 | | 11796 | |
| 11748 | // Validation above ensured these will succeed. | 11797 | // Validation above ensured these will succeed. |
| 11749 | const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], "") catch unreachable; | 11798 | 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; | 11799 | 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 | 11800 | 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))) | 11801 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 11753 | { | 11802 | { |
| ... | @@ -11757,7 +11806,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11757,7 +11806,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11757 | .normal, | 11806 | .normal, |
| 11758 | body, | 11807 | body, |
| 11759 | info.capture, | 11808 | info.capture, |
| 11760 | .{ .multi_capture = @as(u32, @intCast(multi_i)) }, | 11809 | .{ .multi_capture = @intCast(multi_i) }, |
| 11761 | undefined, // case_vals may be undefined for ranges | 11810 | undefined, // case_vals may be undefined for ranges |
| 11762 | if (info.is_inline) operand else .none, | 11811 | if (info.is_inline) operand else .none, |
| 11763 | info.has_tag_capture, | 11812 | info.has_tag_capture, |
| ... | @@ -11771,7 +11820,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11771,7 +11820,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11771 | } | 11820 | } |
| 11772 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand); | 11821 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand); |
| 11773 | if (empty_enum) { | 11822 | if (empty_enum) { |
| 11774 | return Air.Inst.Ref.void_value; | 11823 | return .void_value; |
| 11775 | } | 11824 | } |
| 11776 | | 11825 | |
| 11777 | return spa.resolveProngComptime( | 11826 | return spa.resolveProngComptime( |
| ... | @@ -11789,13 +11838,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11789,13 +11838,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11789 | | 11838 | |
| 11790 | if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) { | 11839 | if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) { |
| 11791 | if (empty_enum) { | 11840 | if (empty_enum) { |
| 11792 | return Air.Inst.Ref.void_value; | 11841 | return .void_value; |
| 11793 | } | 11842 | } |
| 11794 | if (special_prong == .none) { | 11843 | if (special_prong == .none) { |
| 11795 | return sema.fail(block, src, "switch must handle all possibilities", .{}); | 11844 | return sema.fail(block, src, "switch must handle all possibilities", .{}); |
| 11796 | } | 11845 | } |
| 11797 | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src)) { | 11846 | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src)) { |
| 11798 | return Air.Inst.Ref.unreachable_value; | 11847 | return .unreachable_value; |
| 11799 | } | 11848 | } |
| 11800 | if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and | 11849 | if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and |
| 11801 | (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) | 11850 | (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) |
| ... | @@ -11819,10 +11868,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11819,10 +11868,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11819 | } | 11868 | } |
| 11820 | | 11869 | |
| 11821 | if (child_block.is_comptime) { | 11870 | if (child_block.is_comptime) { |
| 11822 | _ = sema.resolveConstValue(&child_block, operand_src, operand, "condition in comptime switch must be comptime-known") catch |err| { | 11871 | _ = 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); | 11872 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", |
| 11824 | return err; | 11873 | .block_comptime_reason = child_block.comptime_reason, |
| 11825 | }; | 11874 | }); |
| 11826 | unreachable; | 11875 | unreachable; |
| 11827 | } | 11876 | } |
| 11828 | | 11877 | |
| ... | @@ -11842,7 +11891,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11842,7 +11891,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11842 | var scalar_i: usize = 0; | 11891 | var scalar_i: usize = 0; |
| 11843 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { | 11892 | while (scalar_i < scalar_cases_len) : (scalar_i += 1) { |
| 11844 | extra_index += 1; | 11893 | extra_index += 1; |
| 11845 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11894 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11846 | extra_index += 1; | 11895 | extra_index += 1; |
| 11847 | const body = sema.code.extra[extra_index..][0..info.body_len]; | 11896 | const body = sema.code.extra[extra_index..][0..info.body_len]; |
| 11848 | extra_index += info.body_len; | 11897 | extra_index += info.body_len; |
| ... | @@ -11857,7 +11906,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11857,7 +11906,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11857 | // `item` is already guaranteed to be constant known. | 11906 | // `item` is already guaranteed to be constant known. |
| 11858 | | 11907 | |
| 11859 | const analyze_body = if (union_originally) blk: { | 11908 | const analyze_body = if (union_originally) blk: { |
| 11860 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item, "") catch unreachable; | 11909 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable; |
| 11861 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); | 11910 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); |
| 11862 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 11911 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 11863 | } else true; | 11912 | } else true; |
| ... | @@ -11870,7 +11919,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11870,7 +11919,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11870 | .normal, | 11919 | .normal, |
| 11871 | body, | 11920 | body, |
| 11872 | info.capture, | 11921 | info.capture, |
| 11873 | .{ .scalar_capture = @as(u32, @intCast(scalar_i)) }, | 11922 | .{ .scalar_capture = @intCast(scalar_i) }, |
| 11874 | &.{item}, | 11923 | &.{item}, |
| 11875 | if (info.is_inline) item else .none, | 11924 | if (info.is_inline) item else .none, |
| 11876 | info.has_tag_capture, | 11925 | info.has_tag_capture, |
| ... | @@ -11883,7 +11932,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11883,7 +11932,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11883 | | 11932 | |
| 11884 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 11933 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 11885 | cases_extra.appendAssumeCapacity(1); // items_len | 11934 | cases_extra.appendAssumeCapacity(1); // items_len |
| 11886 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 11935 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 11887 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); | 11936 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| 11888 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 11937 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 11889 | } | 11938 | } |
| ... | @@ -11903,7 +11952,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11903,7 +11952,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11903 | extra_index += 1; | 11952 | extra_index += 1; |
| 11904 | const ranges_len = sema.code.extra[extra_index]; | 11953 | const ranges_len = sema.code.extra[extra_index]; |
| 11905 | extra_index += 1; | 11954 | extra_index += 1; |
| 11906 | const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index])); | 11955 | const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]); |
| 11907 | extra_index += 1 + items_len; | 11956 | extra_index += 1 + items_len; |
| 11908 | | 11957 | |
| 11909 | const items = case_vals.items[case_val_idx..][0..items_len]; | 11958 | const items = case_vals.items[case_val_idx..][0..items_len]; |
| ... | @@ -11946,7 +11995,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11946,7 +11995,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11946 | | 11995 | |
| 11947 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 11996 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { |
| 11948 | error.NeededSourceLocation => { | 11997 | error.NeededSourceLocation => { |
| 11949 | const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } }; | 11998 | const case_src = Module.SwitchProngSrc{ |
| | 11999 | .range = .{ .prong = multi_i, .item = range_i }, |
| | 12000 | }; |
| 11950 | const decl = mod.declPtr(case_block.src_decl); | 12001 | const decl = mod.declPtr(case_block.src_decl); |
| 11951 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | 12002 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); |
| 11952 | unreachable; | 12003 | unreachable; |
| ... | @@ -11968,7 +12019,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11968,7 +12019,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11968 | | 12019 | |
| 11969 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12020 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 11970 | cases_extra.appendAssumeCapacity(1); // items_len | 12021 | cases_extra.appendAssumeCapacity(1); // items_len |
| 11971 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12022 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 11972 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); | 12023 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 11973 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12024 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 11974 | | 12025 | |
| ... | @@ -11990,7 +12041,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11990,7 +12041,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11990 | | 12041 | |
| 11991 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 12042 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { |
| 11992 | error.NeededSourceLocation => { | 12043 | error.NeededSourceLocation => { |
| 11993 | const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } }; | 12044 | const case_src = Module.SwitchProngSrc{ |
| | 12045 | .multi = .{ .prong = multi_i, .item = @intCast(item_i) }, |
| | 12046 | }; |
| 11994 | const decl = mod.declPtr(case_block.src_decl); | 12047 | const decl = mod.declPtr(case_block.src_decl); |
| 11995 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | 12048 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); |
| 11996 | unreachable; | 12049 | unreachable; |
| ... | @@ -12016,7 +12069,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12016,7 +12069,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12016 | | 12069 | |
| 12017 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12070 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12018 | cases_extra.appendAssumeCapacity(1); // items_len | 12071 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12019 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12072 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12020 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); | 12073 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| 12021 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12074 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12022 | } | 12075 | } |
| ... | @@ -12035,7 +12088,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12035,7 +12088,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12035 | | 12088 | |
| 12036 | const analyze_body = if (union_originally) | 12089 | const analyze_body = if (union_originally) |
| 12037 | for (items) |item| { | 12090 | for (items) |item| { |
| 12038 | const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable; | 12091 | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 12039 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); | 12092 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod); |
| 12040 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; | 12093 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12041 | } else false | 12094 | } else false |
| ... | @@ -12064,8 +12117,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12064,8 +12117,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12064 | try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len + | 12117 | try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len + |
| 12065 | case_block.instructions.items.len); | 12118 | case_block.instructions.items.len); |
| 12066 | | 12119 | |
| 12067 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(items.len))); | 12120 | cases_extra.appendAssumeCapacity(@intCast(items.len)); |
| 12068 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12121 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12069 | | 12122 | |
| 12070 | for (items) |item| { | 12123 | for (items) |item| { |
| 12071 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); | 12124 | cases_extra.appendAssumeCapacity(@intFromEnum(item)); |
| ... | @@ -12160,8 +12213,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12160,8 +12213,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12160 | | 12213 | |
| 12161 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = | 12214 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = |
| 12162 | sema.addExtraAssumeCapacity(Air.CondBr{ | 12215 | sema.addExtraAssumeCapacity(Air.CondBr{ |
| 12163 | .then_body_len = @as(u32, @intCast(prev_then_body.len)), | 12216 | .then_body_len = @intCast(prev_then_body.len), |
| 12164 | .else_body_len = @as(u32, @intCast(cond_body.len)), | 12217 | .else_body_len = @intCast(cond_body.len), |
| 12165 | }); | 12218 | }); |
| 12166 | sema.air_extra.appendSliceAssumeCapacity(prev_then_body); | 12219 | sema.air_extra.appendSliceAssumeCapacity(prev_then_body); |
| 12167 | sema.air_extra.appendSliceAssumeCapacity(cond_body); | 12220 | sema.air_extra.appendSliceAssumeCapacity(cond_body); |
| ... | @@ -12186,7 +12239,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12186,7 +12239,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12186 | if (f != null) continue; | 12239 | if (f != null) continue; |
| 12187 | cases_len += 1; | 12240 | cases_len += 1; |
| 12188 | | 12241 | |
| 12189 | const item_val = try mod.enumValueFieldIndex(operand_ty, @as(u32, @intCast(i))); | 12242 | const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(i)); |
| 12190 | const item_ref = Air.internedToRef(item_val.toIntern()); | 12243 | const item_ref = Air.internedToRef(item_val.toIntern()); |
| 12191 | | 12244 | |
| 12192 | case_block.instructions.shrinkRetainingCapacity(0); | 12245 | case_block.instructions.shrinkRetainingCapacity(0); |
| ... | @@ -12217,7 +12270,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12217,7 +12270,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12217 | | 12270 | |
| 12218 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12271 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12219 | cases_extra.appendAssumeCapacity(1); // items_len | 12272 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12220 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12273 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12221 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); | 12274 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12222 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12275 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12223 | } | 12276 | } |
| ... | @@ -12258,7 +12311,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12258,7 +12311,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12258 | | 12311 | |
| 12259 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12312 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12260 | cases_extra.appendAssumeCapacity(1); // items_len | 12313 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12261 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12314 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12262 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); | 12315 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12263 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12316 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12264 | } | 12317 | } |
| ... | @@ -12289,7 +12342,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12289,7 +12342,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12289 | | 12342 | |
| 12290 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12343 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12291 | cases_extra.appendAssumeCapacity(1); // items_len | 12344 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12292 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12345 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12293 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); | 12346 | cases_extra.appendAssumeCapacity(@intFromEnum(item_ref)); |
| 12294 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12347 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12295 | } | 12348 | } |
| ... | @@ -12310,14 +12363,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12310,14 +12363,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12310 | special.body, | 12363 | special.body, |
| 12311 | special.capture, | 12364 | special.capture, |
| 12312 | .special_capture, | 12365 | .special_capture, |
| 12313 | &.{Air.Inst.Ref.bool_true}, | 12366 | &.{.bool_true}, |
| 12314 | Air.Inst.Ref.bool_true, | 12367 | .bool_true, |
| 12315 | special.has_tag_capture, | 12368 | special.has_tag_capture, |
| 12316 | ); | 12369 | ); |
| 12317 | | 12370 | |
| 12318 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12371 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12319 | cases_extra.appendAssumeCapacity(1); // items_len | 12372 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12320 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12373 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12321 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true)); | 12374 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true)); |
| 12322 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12375 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12323 | } | 12376 | } |
| ... | @@ -12336,14 +12389,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12336,14 +12389,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12336 | special.body, | 12389 | special.body, |
| 12337 | special.capture, | 12390 | special.capture, |
| 12338 | .special_capture, | 12391 | .special_capture, |
| 12339 | &.{Air.Inst.Ref.bool_false}, | 12392 | &.{.bool_false}, |
| 12340 | Air.Inst.Ref.bool_false, | 12393 | .bool_false, |
| 12341 | special.has_tag_capture, | 12394 | special.has_tag_capture, |
| 12342 | ); | 12395 | ); |
| 12343 | | 12396 | |
| 12344 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); | 12397 | try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len); |
| 12345 | cases_extra.appendAssumeCapacity(1); // items_len | 12398 | cases_extra.appendAssumeCapacity(1); // items_len |
| 12346 | cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len))); | 12399 | cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len)); |
| 12347 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false)); | 12400 | cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false)); |
| 12348 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12401 | cases_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| 12349 | } | 12402 | } |
| ... | @@ -12412,8 +12465,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12412,8 +12465,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12412 | | 12465 | |
| 12413 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = | 12466 | sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload = |
| 12414 | sema.addExtraAssumeCapacity(Air.CondBr{ | 12467 | sema.addExtraAssumeCapacity(Air.CondBr{ |
| 12415 | .then_body_len = @as(u32, @intCast(prev_then_body.len)), | 12468 | .then_body_len = @intCast(prev_then_body.len), |
| 12416 | .else_body_len = @as(u32, @intCast(case_block.instructions.items.len)), | 12469 | .else_body_len = @intCast(case_block.instructions.items.len), |
| 12417 | }); | 12470 | }); |
| 12418 | sema.air_extra.appendSliceAssumeCapacity(prev_then_body); | 12471 | sema.air_extra.appendSliceAssumeCapacity(prev_then_body); |
| 12419 | sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items); | 12472 | sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items); |
| ... | @@ -12427,8 +12480,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12427,8 +12480,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12427 | _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{ | 12480 | _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{ |
| 12428 | .operand = operand, | 12481 | .operand = operand, |
| 12429 | .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{ | 12482 | .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{ |
| 12430 | .cases_len = @as(u32, @intCast(cases_len)), | 12483 | .cases_len = @intCast(cases_len), |
| 12431 | .else_body_len = @as(u32, @intCast(final_else_body.len)), | 12484 | .else_body_len = @intCast(final_else_body.len), |
| 12432 | }), | 12485 | }), |
| 12433 | } } }); | 12486 | } } }); |
| 12434 | sema.air_extra.appendSliceAssumeCapacity(cases_extra.items); | 12487 | sema.air_extra.appendSliceAssumeCapacity(cases_extra.items); |
| ... | @@ -12535,10 +12588,12 @@ fn resolveSwitchItemVal( | ... | @@ -12535,10 +12588,12 @@ fn resolveSwitchItemVal( |
| 12535 | else => |e| return e, | 12588 | else => |e| return e, |
| 12536 | }; | 12589 | }; |
| 12537 | | 12590 | |
| 12538 | const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, "") catch |err| switch (err) { | 12591 | const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) { |
| 12539 | error.NeededSourceLocation => { | 12592 | error.NeededSourceLocation => { |
| 12540 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 12593 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 12541 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | 12594 | _ = try sema.resolveConstValue(block, src, item, .{ |
| | 12595 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| | 12596 | }); |
| 12542 | unreachable; | 12597 | unreachable; |
| 12543 | }, | 12598 | }, |
| 12544 | else => |e| return e, | 12599 | else => |e| return e, |
| ... | @@ -12662,7 +12717,7 @@ fn validateSwitchDupe( | ... | @@ -12662,7 +12717,7 @@ fn validateSwitchDupe( |
| 12662 | ); | 12717 | ); |
| 12663 | break :msg msg; | 12718 | break :msg msg; |
| 12664 | }; | 12719 | }; |
| 12665 | return sema.failWithOwnedErrorMsg(msg); | 12720 | return sema.failWithOwnedErrorMsg(block, msg); |
| 12666 | } | 12721 | } |
| 12667 | | 12722 | |
| 12668 | fn validateSwitchItemBool( | 12723 | fn validateSwitchItemBool( |
| ... | @@ -12736,7 +12791,7 @@ fn validateSwitchNoRange( | ... | @@ -12736,7 +12791,7 @@ fn validateSwitchNoRange( |
| 12736 | ); | 12791 | ); |
| 12737 | break :msg msg; | 12792 | break :msg msg; |
| 12738 | }; | 12793 | }; |
| 12739 | return sema.failWithOwnedErrorMsg(msg); | 12794 | return sema.failWithOwnedErrorMsg(block, msg); |
| 12740 | } | 12795 | } |
| 12741 | | 12796 | |
| 12742 | fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref, operand_src: LazySrcLoc) !bool { | 12797 | fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref, operand_src: LazySrcLoc) !bool { |
| ... | @@ -12856,7 +12911,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12856,7 +12911,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12856 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 12911 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12857 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 12912 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 12858 | const ty = try sema.resolveType(block, ty_src, extra.lhs); | 12913 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 12859 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, "field name must be comptime-known"); | 12914 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ |
| | 12915 | .needed_comptime_reason = "field name must be comptime-known", |
| | 12916 | }); |
| 12860 | try sema.resolveTypeFields(ty); | 12917 | try sema.resolveTypeFields(ty); |
| 12861 | const ip = &mod.intern_pool; | 12918 | const ip = &mod.intern_pool; |
| 12862 | | 12919 | |
| ... | @@ -12897,11 +12954,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12897,11 +12954,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12897 | ty.fmt(mod), | 12954 | ty.fmt(mod), |
| 12898 | }); | 12955 | }); |
| 12899 | }; | 12956 | }; |
| 12900 | if (has_field) { | 12957 | return if (has_field) .bool_true else .bool_false; |
| 12901 | return Air.Inst.Ref.bool_true; | | |
| 12902 | } else { | | |
| 12903 | return Air.Inst.Ref.bool_false; | | |
| 12904 | } | | |
| 12905 | } | 12958 | } |
| 12906 | | 12959 | |
| 12907 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12960 | fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -12912,19 +12965,21 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -12912,19 +12965,21 @@ 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 }; | 12965 | 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 }; | 12966 | 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); | 12967 | 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"); | 12968 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| | 12969 | .needed_comptime_reason = "decl name must be comptime-known", |
| | 12970 | }); |
| 12916 | | 12971 | |
| 12917 | try sema.checkNamespaceType(block, lhs_src, container_type); | 12972 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 12918 | | 12973 | |
| 12919 | const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse | 12974 | const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse |
| 12920 | return Air.Inst.Ref.bool_false; | 12975 | return .bool_false; |
| 12921 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { | 12976 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| { |
| 12922 | const decl = mod.declPtr(decl_index); | 12977 | const decl = mod.declPtr(decl_index); |
| 12923 | if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) { | 12978 | if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) { |
| 12924 | return Air.Inst.Ref.bool_true; | 12979 | return .bool_true; |
| 12925 | } | 12980 | } |
| 12926 | } | 12981 | } |
| 12927 | return Air.Inst.Ref.bool_false; | 12982 | return .bool_false; |
| 12928 | } | 12983 | } |
| 12929 | | 12984 | |
| 12930 | fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 12985 | fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -12965,7 +13020,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -12965,7 +13020,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12965 | const mod = sema.mod; | 13020 | const mod = sema.mod; |
| 12966 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 13021 | 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 }; | 13022 | 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"); | 13023 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| | 13024 | .needed_comptime_reason = "file path name must be comptime-known", |
| | 13025 | }); |
| 12969 | | 13026 | |
| 12970 | if (name.len == 0) { | 13027 | if (name.len == 0) { |
| 12971 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | 13028 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); |
| ... | @@ -13588,8 +13645,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13588,8 +13645,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13588 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); | 13645 | 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); | 13646 | 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); | 13647 | 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"); | 13648 | 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"); | 13649 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13650 | }); |
| | 13651 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| | 13652 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13653 | }); |
| 13593 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { | 13654 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| 13594 | break :s lhs_sent_casted_val; | 13655 | break :s lhs_sent_casted_val; |
| 13595 | } else { | 13656 | } else { |
| ... | @@ -13597,14 +13658,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13597,14 +13658,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13597 | } | 13658 | } |
| 13598 | } else { | 13659 | } else { |
| 13599 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 13660 | 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"); | 13661 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{ |
| | 13662 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13663 | }); |
| 13601 | break :s lhs_sent_casted_val; | 13664 | break :s lhs_sent_casted_val; |
| 13602 | } | 13665 | } |
| 13603 | } else { | 13666 | } else { |
| 13604 | if (rhs_info.sentinel) |rhs_sent_val| { | 13667 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 13605 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); | 13668 | 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); | 13669 | 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"); | 13670 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| | 13671 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| | 13672 | }); |
| 13608 | break :s rhs_sent_casted_val; | 13673 | break :s rhs_sent_casted_val; |
| 13609 | } else { | 13674 | } else { |
| 13610 | break :s null; | 13675 | break :s null; |
| ... | @@ -13662,7 +13727,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13662,7 +13727,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; | 13727 | 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()); | 13728 | 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); | 13729 | 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, ""); | 13730 | 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); | 13731 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13667 | } | 13732 | } |
| 13668 | while (elem_i < result_len) : (elem_i += 1) { | 13733 | while (elem_i < result_len) : (elem_i += 1) { |
| ... | @@ -13671,7 +13736,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13671,7 +13736,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; | 13736 | 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()); | 13737 | 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); | 13738 | 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, ""); | 13739 | 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); | 13740 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13676 | } | 13741 | } |
| 13677 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ | 13742 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ |
| ... | @@ -13748,7 +13813,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins | ... | @@ -13748,7 +13813,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 13748 | // has a sentinel, and this code should compute the length based | 13813 | // has a sentinel, and this code should compute the length based |
| 13749 | // on the sentinel value. | 13814 | // on the sentinel value. |
| 13750 | .Slice, .Many => { | 13815 | .Slice, .Many => { |
| 13751 | const val = try sema.resolveConstValue(block, src, operand, "slice value being concatenated must be comptime-known"); | 13816 | const val = try sema.resolveConstValue(block, src, operand, .{ |
| | 13817 | .needed_comptime_reason = "slice value being concatenated must be comptime-known", |
| | 13818 | }); |
| 13752 | return Type.ArrayInfo{ | 13819 | return Type.ArrayInfo{ |
| 13753 | .elem_type = ptr_info.child.toType(), | 13820 | .elem_type = ptr_info.child.toType(), |
| 13754 | .sentinel = switch (ptr_info.sentinel) { | 13821 | .sentinel = switch (ptr_info.sentinel) { |
| ... | @@ -13842,7 +13909,7 @@ fn analyzeTupleMul( | ... | @@ -13842,7 +13909,7 @@ fn analyzeTupleMul( |
| 13842 | var i: u32 = 0; | 13909 | var i: u32 = 0; |
| 13843 | while (i < tuple_len) : (i += 1) { | 13910 | while (i < tuple_len) : (i += 1) { |
| 13844 | const operand_src = lhs_src; // TODO better source location | 13911 | const operand_src = lhs_src; // TODO better source location |
| 13845 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @as(u32, @intCast(i)), operand_ty); | 13912 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); |
| 13846 | } | 13913 | } |
| 13847 | i = 1; | 13914 | i = 1; |
| 13848 | while (i < factor) : (i += 1) { | 13915 | while (i < factor) : (i += 1) { |
| ... | @@ -13868,7 +13935,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13868,7 +13935,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13868 | | 13935 | |
| 13869 | if (lhs_ty.isTuple(mod)) { | 13936 | if (lhs_ty.isTuple(mod)) { |
| 13870 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 13937 | // 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"); | 13938 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ |
| | 13939 | .needed_comptime_reason = "array multiplication factor must be comptime-known", |
| | 13940 | }); |
| 13872 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); | 13941 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); |
| 13873 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); | 13942 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); |
| 13874 | } | 13943 | } |
| ... | @@ -13886,11 +13955,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13886,11 +13955,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13886 | } | 13955 | } |
| 13887 | break :msg msg; | 13956 | break :msg msg; |
| 13888 | }; | 13957 | }; |
| 13889 | return sema.failWithOwnedErrorMsg(msg); | 13958 | return sema.failWithOwnedErrorMsg(block, msg); |
| 13890 | }; | 13959 | }; |
| 13891 | | 13960 | |
| 13892 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 13961 | // 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"); | 13962 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ |
| | 13963 | .needed_comptime_reason = "array multiplication factor must be comptime-known", |
| | 13964 | }); |
| 13894 | | 13965 | |
| 13895 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch | 13966 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch |
| 13896 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); | 13967 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| ... | @@ -15886,10 +15957,10 @@ fn analyzePtrArithmetic( | ... | @@ -15886,10 +15957,10 @@ fn analyzePtrArithmetic( |
| 15886 | // The resulting pointer is aligned to the lcd between the offset (an | 15957 | // The resulting pointer is aligned to the lcd between the offset (an |
| 15887 | // arbitrary number) and the alignment factor (always a power of two, | 15958 | // arbitrary number) and the alignment factor (always a power of two, |
| 15888 | // non zero). | 15959 | // non zero). |
| 15889 | const new_align = @as(Alignment, @enumFromInt(@min( | 15960 | const new_align: Alignment = @enumFromInt(@min( |
| 15890 | @ctz(addend), | 15961 | @ctz(addend), |
| 15891 | @intFromEnum(ptr_info.flags.alignment), | 15962 | @intFromEnum(ptr_info.flags.alignment), |
| 15892 | ))); | 15963 | )); |
| 15893 | assert(new_align != .none); | 15964 | assert(new_align != .none); |
| 15894 | | 15965 | |
| 15895 | break :t try mod.ptrType(.{ | 15966 | break :t try mod.ptrType(.{ |
| ... | @@ -15968,15 +16039,17 @@ fn zirAsm( | ... | @@ -15968,15 +16039,17 @@ fn zirAsm( |
| 15968 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); | 16039 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); |
| 15969 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 16040 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 15970 | const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node }; | 16041 | const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node }; |
| 15971 | const outputs_len = @as(u5, @truncate(extended.small)); | 16042 | const outputs_len: u5 = @truncate(extended.small); |
| 15972 | const inputs_len = @as(u5, @truncate(extended.small >> 5)); | 16043 | const inputs_len: u5 = @truncate(extended.small >> 5); |
| 15973 | const clobbers_len = @as(u5, @truncate(extended.small >> 10)); | 16044 | const clobbers_len: u5 = @truncate(extended.small >> 10); |
| 15974 | const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0; | 16045 | const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0; |
| 15975 | const is_global_assembly = sema.func_index == .none; | 16046 | const is_global_assembly = sema.func_index == .none; |
| 15976 | | 16047 | |
| 15977 | const asm_source: []const u8 = if (tmpl_is_expr) blk: { | 16048 | const asm_source: []const u8 = if (tmpl_is_expr) blk: { |
| 15978 | const tmpl = @as(Zir.Inst.Ref, @enumFromInt(extra.data.asm_source)); | 16049 | 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"); | 16050 | const s: []const u8 = try sema.resolveConstString(block, src, tmpl, .{ |
| | 16051 | .needed_comptime_reason = "assembly code must be comptime-known", |
| | 16052 | }); |
| 15980 | break :blk s; | 16053 | break :blk s; |
| 15981 | } else sema.code.nullTerminatedString(extra.data.asm_source); | 16054 | } else sema.code.nullTerminatedString(extra.data.asm_source); |
| 15982 | | 16055 | |
| ... | @@ -15994,7 +16067,7 @@ fn zirAsm( | ... | @@ -15994,7 +16067,7 @@ fn zirAsm( |
| 15994 | return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{}); | 16067 | return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{}); |
| 15995 | } | 16068 | } |
| 15996 | try sema.mod.addGlobalAssembly(sema.owner_decl_index, asm_source); | 16069 | try sema.mod.addGlobalAssembly(sema.owner_decl_index, asm_source); |
| 15997 | return Air.Inst.Ref.void_value; | 16070 | return .void_value; |
| 15998 | } | 16071 | } |
| 15999 | | 16072 | |
| 16000 | if (block.is_comptime) { | 16073 | if (block.is_comptime) { |
| ... | @@ -16076,9 +16149,9 @@ fn zirAsm( | ... | @@ -16076,9 +16149,9 @@ fn zirAsm( |
| 16076 | .data = .{ .ty_pl = .{ | 16149 | .data = .{ .ty_pl = .{ |
| 16077 | .ty = expr_ty, | 16150 | .ty = expr_ty, |
| 16078 | .payload = sema.addExtraAssumeCapacity(Air.Asm{ | 16151 | .payload = sema.addExtraAssumeCapacity(Air.Asm{ |
| 16079 | .source_len = @as(u32, @intCast(asm_source.len)), | 16152 | .source_len = @intCast(asm_source.len), |
| 16080 | .outputs_len = outputs_len, | 16153 | .outputs_len = outputs_len, |
| 16081 | .inputs_len = @as(u32, @intCast(args.len)), | 16154 | .inputs_len = @intCast(args.len), |
| 16082 | .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @as(u32, @intCast(clobbers.len)), | 16155 | .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @as(u32, @intCast(clobbers.len)), |
| 16083 | }), | 16156 | }), |
| 16084 | } }, | 16157 | } }, |
| ... | @@ -16141,11 +16214,7 @@ fn zirCmpEq( | ... | @@ -16141,11 +16214,7 @@ fn zirCmpEq( |
| 16141 | const rhs_ty_tag = rhs_ty.zigTypeTag(mod); | 16214 | const rhs_ty_tag = rhs_ty.zigTypeTag(mod); |
| 16142 | if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) { | 16215 | if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) { |
| 16143 | // null == null, null != null | 16216 | // null == null, null != null |
| 16144 | if (op == .eq) { | 16217 | return if (op == .eq) .bool_true else .bool_false; |
| 16145 | return Air.Inst.Ref.bool_true; | | |
| 16146 | } else { | | |
| 16147 | return Air.Inst.Ref.bool_false; | | |
| 16148 | } | | |
| 16149 | } | 16218 | } |
| 16150 | | 16219 | |
| 16151 | // comparing null with optionals | 16220 | // comparing null with optionals |
| ... | @@ -16177,11 +16246,10 @@ fn zirCmpEq( | ... | @@ -16177,11 +16246,10 @@ fn zirCmpEq( |
| 16177 | } | 16246 | } |
| 16178 | const lkey = mod.intern_pool.indexToKey(lval.toIntern()); | 16247 | const lkey = mod.intern_pool.indexToKey(lval.toIntern()); |
| 16179 | const rkey = mod.intern_pool.indexToKey(rval.toIntern()); | 16248 | const rkey = mod.intern_pool.indexToKey(rval.toIntern()); |
| 16180 | if ((lkey.err.name == rkey.err.name) == (op == .eq)) { | 16249 | return if ((lkey.err.name == rkey.err.name) == (op == .eq)) |
| 16181 | return Air.Inst.Ref.bool_true; | 16250 | .bool_true |
| 16182 | } else { | 16251 | else |
| 16183 | return Air.Inst.Ref.bool_false; | 16252 | .bool_false; |
| 16184 | } | | |
| 16185 | } else { | 16253 | } else { |
| 16186 | break :src rhs_src; | 16254 | break :src rhs_src; |
| 16187 | } | 16255 | } |
| ... | @@ -16195,11 +16263,7 @@ fn zirCmpEq( | ... | @@ -16195,11 +16263,7 @@ fn zirCmpEq( |
| 16195 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { | 16263 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { |
| 16196 | const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs); | 16264 | const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs); |
| 16197 | const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs); | 16265 | const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs); |
| 16198 | if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) { | 16266 | return if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) .bool_true else .bool_false; |
| 16199 | return Air.Inst.Ref.bool_true; | | |
| 16200 | } else { | | |
| 16201 | return Air.Inst.Ref.bool_false; | | |
| 16202 | } | | |
| 16203 | } | 16267 | } |
| 16204 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true); | 16268 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true); |
| 16205 | } | 16269 | } |
| ... | @@ -16224,7 +16288,7 @@ fn analyzeCmpUnionTag( | ... | @@ -16224,7 +16288,7 @@ fn analyzeCmpUnionTag( |
| 16224 | try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); | 16288 | try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); |
| 16225 | break :msg msg; | 16289 | break :msg msg; |
| 16226 | }; | 16290 | }; |
| 16227 | return sema.failWithOwnedErrorMsg(msg); | 16291 | return sema.failWithOwnedErrorMsg(block, msg); |
| 16228 | }; | 16292 | }; |
| 16229 | // Coerce both the union and the tag to the union's tag type, and then execute the | 16293 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 16230 | // enum comparison codepath. | 16294 | // enum comparison codepath. |
| ... | @@ -16235,7 +16299,7 @@ fn analyzeCmpUnionTag( | ... | @@ -16235,7 +16299,7 @@ fn analyzeCmpUnionTag( |
| 16235 | if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool); | 16299 | if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool); |
| 16236 | const field_ty = union_ty.unionFieldType(enum_val, mod); | 16300 | const field_ty = union_ty.unionFieldType(enum_val, mod); |
| 16237 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 16301 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 16238 | return Air.Inst.Ref.bool_false; | 16302 | return .bool_false; |
| 16239 | } | 16303 | } |
| 16240 | } | 16304 | } |
| 16241 | | 16305 | |
| ... | @@ -16343,11 +16407,10 @@ fn cmpSelf( | ... | @@ -16343,11 +16407,10 @@ fn cmpSelf( |
| 16343 | return Air.internedToRef(cmp_val.toIntern()); | 16407 | return Air.internedToRef(cmp_val.toIntern()); |
| 16344 | } | 16408 | } |
| 16345 | | 16409 | |
| 16346 | if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) { | 16410 | return if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) |
| 16347 | return Air.Inst.Ref.bool_true; | 16411 | .bool_true |
| 16348 | } else { | 16412 | else |
| 16349 | return Air.Inst.Ref.bool_false; | 16413 | .bool_false; |
| 16350 | } | | |
| 16351 | } else { | 16414 | } else { |
| 16352 | if (resolved_type.zigTypeTag(mod) == .Bool) { | 16415 | if (resolved_type.zigTypeTag(mod) == .Bool) { |
| 16353 | // We can lower bool eq/neq more efficiently. | 16416 | // We can lower bool eq/neq more efficiently. |
| ... | @@ -16486,7 +16549,7 @@ fn zirThis( | ... | @@ -16486,7 +16549,7 @@ fn zirThis( |
| 16486 | ) CompileError!Air.Inst.Ref { | 16549 | ) CompileError!Air.Inst.Ref { |
| 16487 | const mod = sema.mod; | 16550 | const mod = sema.mod; |
| 16488 | const this_decl_index = mod.namespaceDeclIndex(block.namespace); | 16551 | const this_decl_index = mod.namespaceDeclIndex(block.namespace); |
| 16489 | const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand))); | 16552 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 16490 | return sema.analyzeDeclVal(block, src, this_decl_index); | 16553 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 16491 | } | 16554 | } |
| 16492 | | 16555 | |
| ... | @@ -16560,7 +16623,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -16560,7 +16623,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 16560 | // TODO add "declared here" note | 16623 | // TODO add "declared here" note |
| 16561 | break :msg msg; | 16624 | break :msg msg; |
| 16562 | }; | 16625 | }; |
| 16563 | return sema.failWithOwnedErrorMsg(msg); | 16626 | return sema.failWithOwnedErrorMsg(block, msg); |
| 16564 | } | 16627 | } |
| 16565 | | 16628 | |
| 16566 | if (capture == .runtime_val and !block.is_typeof and !block.is_comptime and sema.func_index != .none) { | 16629 | if (capture == .runtime_val and !block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| ... | @@ -16590,7 +16653,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -16590,7 +16653,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 16590 | // TODO add "declared here" note | 16653 | // TODO add "declared here" note |
| 16591 | break :msg msg; | 16654 | break :msg msg; |
| 16592 | }; | 16655 | }; |
| 16593 | return sema.failWithOwnedErrorMsg(msg); | 16656 | return sema.failWithOwnedErrorMsg(block, msg); |
| 16594 | } | 16657 | } |
| 16595 | | 16658 | |
| 16596 | switch (capture) { | 16659 | switch (capture) { |
| ... | @@ -16624,7 +16687,7 @@ fn zirFrameAddress( | ... | @@ -16624,7 +16687,7 @@ fn zirFrameAddress( |
| 16624 | block: *Block, | 16687 | block: *Block, |
| 16625 | extended: Zir.Inst.Extended.InstData, | 16688 | extended: Zir.Inst.Extended.InstData, |
| 16626 | ) CompileError!Air.Inst.Ref { | 16689 | ) CompileError!Air.Inst.Ref { |
| 16627 | const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand))); | 16690 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 16628 | try sema.requireRuntimeBlock(block, src, null); | 16691 | try sema.requireRuntimeBlock(block, src, null); |
| 16629 | return try block.addNoOp(.frame_addr); | 16692 | return try block.addNoOp(.frame_addr); |
| 16630 | } | 16693 | } |
| ... | @@ -17223,7 +17286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17223,7 +17286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17223 | else | 17286 | else |
| 17224 | try mod.intern(.{ .int = .{ | 17287 | try mod.intern(.{ .int = .{ |
| 17225 | .ty = .comptime_int_type, | 17288 | .ty = .comptime_int_type, |
| 17226 | .storage = .{ .u64 = @as(u64, @intCast(i)) }, | 17289 | .storage = .{ .u64 = @intCast(i) }, |
| 17227 | } }); | 17290 | } }); |
| 17228 | // TODO: write something like getCoercedInts to avoid needing to dupe | 17291 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17229 | const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i])); | 17292 | const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i])); |
| ... | @@ -17996,10 +18059,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -17996,10 +18059,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17996 | if (try sema.resolveMaybeUndefVal(operand)) |val| { | 18059 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 17997 | return if (val.isUndef(mod)) | 18060 | return if (val.isUndef(mod)) |
| 17998 | mod.undefRef(Type.bool) | 18061 | mod.undefRef(Type.bool) |
| 17999 | else if (val.toBool()) | 18062 | else if (val.toBool()) .bool_false else .bool_true; |
| 18000 | Air.Inst.Ref.bool_false | | |
| 18001 | else | | |
| 18002 | Air.Inst.Ref.bool_true; | | |
| 18003 | } | 18063 | } |
| 18004 | try sema.requireRuntimeBlock(block, src, null); | 18064 | try sema.requireRuntimeBlock(block, src, null); |
| 18005 | return block.addTyOp(.not, Type.bool, operand); | 18065 | return block.addTyOp(.not, Type.bool, operand); |
| ... | @@ -18025,9 +18085,9 @@ fn zirBoolBr( | ... | @@ -18025,9 +18085,9 @@ fn zirBoolBr( |
| 18025 | | 18085 | |
| 18026 | if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { | 18086 | if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { |
| 18027 | if (is_bool_or and lhs_val.toBool()) { | 18087 | if (is_bool_or and lhs_val.toBool()) { |
| 18028 | return Air.Inst.Ref.bool_true; | 18088 | return .bool_true; |
| 18029 | } else if (!is_bool_or and !lhs_val.toBool()) { | 18089 | } else if (!is_bool_or and !lhs_val.toBool()) { |
| 18030 | return Air.Inst.Ref.bool_false; | 18090 | return .bool_false; |
| 18031 | } | 18091 | } |
| 18032 | // comptime-known left-hand side. No need for a block here; the result | 18092 | // comptime-known left-hand side. No need for a block here; the result |
| 18033 | // is simply the rhs expression. Here we rely on there only being 1 | 18093 | // is simply the rhs expression. Here we rely on there only being 1 |
| ... | @@ -18035,7 +18095,7 @@ fn zirBoolBr( | ... | @@ -18035,7 +18095,7 @@ fn zirBoolBr( |
| 18035 | return sema.resolveBody(parent_block, body, inst); | 18095 | return sema.resolveBody(parent_block, body, inst); |
| 18036 | } | 18096 | } |
| 18037 | | 18097 | |
| 18038 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 18098 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 18039 | try sema.air_instructions.append(gpa, .{ | 18099 | try sema.air_instructions.append(gpa, .{ |
| 18040 | .tag = .block, | 18100 | .tag = .block, |
| 18041 | .data = .{ .ty_pl = .{ | 18101 | .data = .{ .ty_pl = .{ |
| ... | @@ -18071,9 +18131,9 @@ fn zirBoolBr( | ... | @@ -18071,9 +18131,9 @@ fn zirBoolBr( |
| 18071 | if (!sema.typeOf(rhs_result).isNoReturn(mod)) { | 18131 | if (!sema.typeOf(rhs_result).isNoReturn(mod)) { |
| 18072 | if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { | 18132 | if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { |
| 18073 | if (is_bool_or and rhs_val.toBool()) { | 18133 | if (is_bool_or and rhs_val.toBool()) { |
| 18074 | return Air.Inst.Ref.bool_true; | 18134 | return .bool_true; |
| 18075 | } else if (!is_bool_or and !rhs_val.toBool()) { | 18135 | } else if (!is_bool_or and !rhs_val.toBool()) { |
| 18076 | return Air.Inst.Ref.bool_false; | 18136 | return .bool_false; |
| 18077 | } | 18137 | } |
| 18078 | } | 18138 | } |
| 18079 | } | 18139 | } |
| ... | @@ -18097,8 +18157,8 @@ fn finishCondBr( | ... | @@ -18097,8 +18157,8 @@ fn finishCondBr( |
| 18097 | @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1); | 18157 | @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1); |
| 18098 | | 18158 | |
| 18099 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 18159 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 18100 | .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)), | 18160 | .then_body_len = @intCast(then_block.instructions.items.len), |
| 18101 | .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)), | 18161 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 18102 | }); | 18162 | }); |
| 18103 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); | 18163 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); |
| 18104 | sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items); | 18164 | sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items); |
| ... | @@ -18109,7 +18169,7 @@ fn finishCondBr( | ... | @@ -18109,7 +18169,7 @@ fn finishCondBr( |
| 18109 | } } }); | 18169 | } } }); |
| 18110 | | 18170 | |
| 18111 | sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity( | 18171 | sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity( |
| 18112 | Air.Block{ .body_len = @as(u32, @intCast(child_block.instructions.items.len)) }, | 18172 | Air.Block{ .body_len = @intCast(child_block.instructions.items.len) }, |
| 18113 | ); | 18173 | ); |
| 18114 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); | 18174 | sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items); |
| 18115 | | 18175 | |
| ... | @@ -18272,8 +18332,8 @@ fn zirCondbr( | ... | @@ -18272,8 +18332,8 @@ fn zirCondbr( |
| 18272 | .data = .{ .pl_op = .{ | 18332 | .data = .{ .pl_op = .{ |
| 18273 | .operand = cond, | 18333 | .operand = cond, |
| 18274 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 18334 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 18275 | .then_body_len = @as(u32, @intCast(true_instructions.len)), | 18335 | .then_body_len = @intCast(true_instructions.len), |
| 18276 | .else_body_len = @as(u32, @intCast(sub_block.instructions.items.len)), | 18336 | .else_body_len = @intCast(sub_block.instructions.items.len), |
| 18277 | }), | 18337 | }), |
| 18278 | } }, | 18338 | } }, |
| 18279 | }); | 18339 | }); |
| ... | @@ -18320,7 +18380,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -18320,7 +18380,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 18320 | .data = .{ .pl_op = .{ | 18380 | .data = .{ .pl_op = .{ |
| 18321 | .operand = err_union, | 18381 | .operand = err_union, |
| 18322 | .payload = sema.addExtraAssumeCapacity(Air.Try{ | 18382 | .payload = sema.addExtraAssumeCapacity(Air.Try{ |
| 18323 | .body_len = @as(u32, @intCast(sub_block.instructions.items.len)), | 18383 | .body_len = @intCast(sub_block.instructions.items.len), |
| 18324 | }), | 18384 | }), |
| 18325 | } }, | 18385 | } }, |
| 18326 | }); | 18386 | }); |
| ... | @@ -18380,7 +18440,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -18380,7 +18440,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18380 | .ty = res_ty_ref, | 18440 | .ty = res_ty_ref, |
| 18381 | .payload = sema.addExtraAssumeCapacity(Air.TryPtr{ | 18441 | .payload = sema.addExtraAssumeCapacity(Air.TryPtr{ |
| 18382 | .ptr = operand, | 18442 | .ptr = operand, |
| 18383 | .body_len = @as(u32, @intCast(sub_block.instructions.items.len)), | 18443 | .body_len = @intCast(sub_block.instructions.items.len), |
| 18384 | }), | 18444 | }), |
| 18385 | } }, | 18445 | } }, |
| 18386 | }); | 18446 | }); |
| ... | @@ -18396,7 +18456,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi | ... | @@ -18396,7 +18456,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi |
| 18396 | const labeled_block = if (!gop.found_existing) blk: { | 18456 | const labeled_block = if (!gop.found_existing) blk: { |
| 18397 | try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1); | 18457 | try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1); |
| 18398 | | 18458 | |
| 18399 | const new_block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 18459 | const new_block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 18400 | gop.value_ptr.* = Air.indexToRef(new_block_inst); | 18460 | gop.value_ptr.* = Air.indexToRef(new_block_inst); |
| 18401 | try sema.air_instructions.append(sema.gpa, .{ | 18461 | try sema.air_instructions.append(sema.gpa, .{ |
| 18402 | .tag = .block, | 18462 | .tag = .block, |
| ... | @@ -18517,7 +18577,7 @@ fn zirRetImplicit( | ... | @@ -18517,7 +18577,7 @@ fn zirRetImplicit( |
| 18517 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 18577 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 18518 | break :msg msg; | 18578 | break :msg msg; |
| 18519 | }; | 18579 | }; |
| 18520 | return sema.failWithOwnedErrorMsg(msg); | 18580 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18521 | } else if (base_tag != .Void) { | 18581 | } else if (base_tag != .Void) { |
| 18522 | const msg = msg: { | 18582 | const msg = msg: { |
| 18523 | const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ | 18583 | const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ |
| ... | @@ -18527,7 +18587,7 @@ fn zirRetImplicit( | ... | @@ -18527,7 +18587,7 @@ fn zirRetImplicit( |
| 18527 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 18587 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 18528 | break :msg msg; | 18588 | break :msg msg; |
| 18529 | }; | 18589 | }; |
| 18530 | return sema.failWithOwnedErrorMsg(msg); | 18590 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18531 | } | 18591 | } |
| 18532 | | 18592 | |
| 18533 | return sema.analyzeRet(block, operand, r_brace_src); | 18593 | return sema.analyzeRet(block, operand, r_brace_src); |
| ... | @@ -18611,8 +18671,8 @@ fn retWithErrTracing( | ... | @@ -18611,8 +18671,8 @@ fn retWithErrTracing( |
| 18611 | @typeInfo(Air.Block).Struct.fields.len + 1); | 18671 | @typeInfo(Air.Block).Struct.fields.len + 1); |
| 18612 | | 18672 | |
| 18613 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 18673 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 18614 | .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)), | 18674 | .then_body_len = @intCast(then_block.instructions.items.len), |
| 18615 | .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)), | 18675 | .else_body_len = @intCast(else_block.instructions.items.len), |
| 18616 | }); | 18676 | }); |
| 18617 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); | 18677 | sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items); |
| 18618 | sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items); | 18678 | sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items); |
| ... | @@ -18749,7 +18809,9 @@ fn analyzeRet( | ... | @@ -18749,7 +18809,9 @@ fn analyzeRet( |
| 18749 | | 18809 | |
| 18750 | if (block.inlining) |inlining| { | 18810 | if (block.inlining) |inlining| { |
| 18751 | if (block.is_comptime) { | 18811 | if (block.is_comptime) { |
| 18752 | _ = try sema.resolveConstMaybeUndefVal(block, src, operand, "value being returned at comptime must be comptime-known"); | 18812 | _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{ |
| | 18813 | .needed_comptime_reason = "value being returned at comptime must be comptime-known", |
| | 18814 | }); |
| 18753 | inlining.comptime_result = operand; | 18815 | inlining.comptime_result = operand; |
| 18754 | return error.ComptimeReturn; | 18816 | return error.ComptimeReturn; |
| 18755 | } | 18817 | } |
| ... | @@ -18767,7 +18829,7 @@ fn analyzeRet( | ... | @@ -18767,7 +18829,7 @@ fn analyzeRet( |
| 18767 | try sema.errNote(block, src, msg, "can only return using assembly", .{}); | 18829 | try sema.errNote(block, src, msg, "can only return using assembly", .{}); |
| 18768 | break :msg msg; | 18830 | break :msg msg; |
| 18769 | }; | 18831 | }; |
| 18770 | return sema.failWithOwnedErrorMsg(msg); | 18832 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18771 | } | 18833 | } |
| 18772 | | 18834 | |
| 18773 | try sema.resolveTypeLayout(sema.fn_ret_ty); | 18835 | try sema.resolveTypeLayout(sema.fn_ret_ty); |
| ... | @@ -18826,18 +18888,22 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18826,18 +18888,22 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18826 | var extra_i = extra.end; | 18888 | var extra_i = extra.end; |
| 18827 | | 18889 | |
| 18828 | const sentinel = if (inst_data.flags.has_sentinel) blk: { | 18890 | const sentinel = if (inst_data.flags.has_sentinel) blk: { |
| 18829 | const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i])); | 18891 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18830 | extra_i += 1; | 18892 | extra_i += 1; |
| 18831 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); | 18893 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 18832 | const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known"); | 18894 | const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{ |
| | 18895 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", |
| | 18896 | }); |
| 18833 | break :blk val.toIntern(); | 18897 | break :blk val.toIntern(); |
| 18834 | } else .none; | 18898 | } else .none; |
| 18835 | | 18899 | |
| 18836 | const abi_align: Alignment = if (inst_data.flags.has_align) blk: { | 18900 | const abi_align: Alignment = if (inst_data.flags.has_align) blk: { |
| 18837 | const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i])); | 18901 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18838 | extra_i += 1; | 18902 | extra_i += 1; |
| 18839 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); | 18903 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); |
| 18840 | const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known"); | 18904 | const val = try sema.resolveConstValue(block, align_src, coerced, .{ |
| | 18905 | .needed_comptime_reason = "pointer alignment must be comptime-known", |
| | 18906 | }); |
| 18841 | // Check if this happens to be the lazy alignment of our element type, in | 18907 | // Check if this happens to be the lazy alignment of our element type, in |
| 18842 | // which case we can make this 0 without resolving it. | 18908 | // which case we can make this 0 without resolving it. |
| 18843 | switch (mod.intern_pool.indexToKey(val.toIntern())) { | 18909 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| ... | @@ -18847,29 +18913,33 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18847,29 +18913,33 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18847 | }, | 18913 | }, |
| 18848 | else => {}, | 18914 | else => {}, |
| 18849 | } | 18915 | } |
| 18850 | const abi_align = @as(u32, @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?)); | 18916 | const abi_align: u32 = @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?); |
| 18851 | try sema.validateAlign(block, align_src, abi_align); | 18917 | try sema.validateAlign(block, align_src, abi_align); |
| 18852 | break :blk Alignment.fromByteUnits(abi_align); | 18918 | break :blk Alignment.fromByteUnits(abi_align); |
| 18853 | } else .none; | 18919 | } else .none; |
| 18854 | | 18920 | |
| 18855 | const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: { | 18921 | const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: { |
| 18856 | const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i])); | 18922 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18857 | extra_i += 1; | 18923 | extra_i += 1; |
| 18858 | break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer); | 18924 | break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer); |
| 18859 | } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic; | 18925 | } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic; |
| 18860 | | 18926 | |
| 18861 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { | 18927 | const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 18862 | const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i])); | 18928 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18863 | extra_i += 1; | 18929 | extra_i += 1; |
| 18864 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known"); | 18930 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{ |
| 18865 | break :blk @as(u16, @intCast(bit_offset)); | 18931 | .needed_comptime_reason = "pointer bit-offset must be comptime-known", |
| | 18932 | }); |
| | 18933 | break :blk @intCast(bit_offset); |
| 18866 | } else 0; | 18934 | } else 0; |
| 18867 | | 18935 | |
| 18868 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 18936 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 18869 | const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i])); | 18937 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18870 | extra_i += 1; | 18938 | extra_i += 1; |
| 18871 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known"); | 18939 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{ |
| 18872 | break :blk @as(u16, @intCast(host_size)); | 18940 | .needed_comptime_reason = "pointer host size must be comptime-known", |
| | 18941 | }); |
| | 18942 | break :blk @intCast(host_size); |
| 18873 | } else 0; | 18943 | } else 0; |
| 18874 | | 18944 | |
| 18875 | if (host_size != 0 and bit_offset >= host_size * 8) { | 18945 | if (host_size != 0 and bit_offset >= host_size * 8) { |
| ... | @@ -18900,7 +18970,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18900,7 +18970,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18900 | try sema.addDeclaredHereNote(msg, elem_ty); | 18970 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 18901 | break :msg msg; | 18971 | break :msg msg; |
| 18902 | }; | 18972 | }; |
| 18903 | return sema.failWithOwnedErrorMsg(msg); | 18973 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18904 | } | 18974 | } |
| 18905 | if (elem_ty.zigTypeTag(mod) == .Opaque) { | 18975 | if (elem_ty.zigTypeTag(mod) == .Opaque) { |
| 18906 | return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{}); | 18976 | return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{}); |
| ... | @@ -18994,9 +19064,11 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -18994,9 +19064,11 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18994 | try sema.addDeclaredHereNote(msg, union_ty); | 19064 | try sema.addDeclaredHereNote(msg, union_ty); |
| 18995 | break :msg msg; | 19065 | break :msg msg; |
| 18996 | }; | 19066 | }; |
| 18997 | return sema.failWithOwnedErrorMsg(msg); | 19067 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18998 | } | 19068 | } |
| 18999 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "name of field being initialized must be comptime-known"); | 19069 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| | 19070 | .needed_comptime_reason = "name of field being initialized must be comptime-known", |
| | 19071 | }); |
| 19000 | const init = try sema.resolveInst(extra.init); | 19072 | const init = try sema.resolveInst(extra.init); |
| 19001 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); | 19073 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); |
| 19002 | } | 19074 | } |
| ... | @@ -19098,13 +19170,15 @@ fn zirStructInit( | ... | @@ -19098,13 +19170,15 @@ fn zirStructInit( |
| 19098 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); | 19170 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 19099 | break :msg msg; | 19171 | break :msg msg; |
| 19100 | }; | 19172 | }; |
| 19101 | return sema.failWithOwnedErrorMsg(msg); | 19173 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19102 | } | 19174 | } |
| 19103 | found_fields[field_index] = item.data.field_type; | 19175 | found_fields[field_index] = item.data.field_type; |
| 19104 | field_inits[field_index] = try sema.resolveInst(item.data.init); | 19176 | field_inits[field_index] = try sema.resolveInst(item.data.init); |
| 19105 | if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| { | 19177 | if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| { |
| 19106 | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { | 19178 | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { |
| 19107 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 19179 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 19180 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 19181 | }); |
| 19108 | }; | 19182 | }; |
| 19109 | | 19183 | |
| 19110 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) { | 19184 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) { |
| ... | @@ -19238,7 +19312,7 @@ fn finishStructInit( | ... | @@ -19238,7 +19312,7 @@ fn finishStructInit( |
| 19238 | ); | 19312 | ); |
| 19239 | } | 19313 | } |
| 19240 | root_msg = null; | 19314 | root_msg = null; |
| 19241 | return sema.failWithOwnedErrorMsg(msg); | 19315 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19242 | } | 19316 | } |
| 19243 | | 19317 | |
| 19244 | // Find which field forces the expression to be runtime, if any. | 19318 | // Find which field forces the expression to be runtime, if any. |
| ... | @@ -19270,7 +19344,7 @@ fn finishStructInit( | ... | @@ -19270,7 +19344,7 @@ fn finishStructInit( |
| 19270 | }); | 19344 | }); |
| 19271 | const alloc = try block.addTy(.alloc, alloc_ty); | 19345 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 19272 | for (field_inits, 0..) |field_init, i_usize| { | 19346 | for (field_inits, 0..) |field_init, i_usize| { |
| 19273 | const i = @as(u32, @intCast(i_usize)); | 19347 | const i: u32 = @intCast(i_usize); |
| 19274 | const field_src = dest_src; | 19348 | const field_src = dest_src; |
| 19275 | const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true); | 19349 | const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true); |
| 19276 | try sema.storePtr(block, dest_src, field_ptr, field_init); | 19350 | try sema.storePtr(block, dest_src, field_ptr, field_init); |
| ... | @@ -19362,7 +19436,7 @@ fn structInitAnon( | ... | @@ -19362,7 +19436,7 @@ fn structInitAnon( |
| 19362 | try sema.errNote(block, prev_source, msg, "other field here", .{}); | 19436 | try sema.errNote(block, prev_source, msg, "other field here", .{}); |
| 19363 | break :msg msg; | 19437 | break :msg msg; |
| 19364 | }; | 19438 | }; |
| 19365 | return sema.failWithOwnedErrorMsg(msg); | 19439 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19366 | } | 19440 | } |
| 19367 | gop.value_ptr.* = i; | 19441 | gop.value_ptr.* = i; |
| 19368 | | 19442 | |
| ... | @@ -19378,7 +19452,7 @@ fn structInitAnon( | ... | @@ -19378,7 +19452,7 @@ fn structInitAnon( |
| 19378 | try sema.addDeclaredHereNote(msg, field_ty.toType()); | 19452 | try sema.addDeclaredHereNote(msg, field_ty.toType()); |
| 19379 | break :msg msg; | 19453 | break :msg msg; |
| 19380 | }; | 19454 | }; |
| 19381 | return sema.failWithOwnedErrorMsg(msg); | 19455 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19382 | } | 19456 | } |
| 19383 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { | 19457 | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 19384 | values[i] = try init_val.intern(field_ty.toType(), mod); | 19458 | values[i] = try init_val.intern(field_ty.toType(), mod); |
| ... | @@ -19423,7 +19497,7 @@ fn structInitAnon( | ... | @@ -19423,7 +19497,7 @@ fn structInitAnon( |
| 19423 | const alloc = try block.addTy(.alloc, alloc_ty); | 19497 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 19424 | var extra_index = extra_end; | 19498 | var extra_index = extra_end; |
| 19425 | for (types, 0..) |field_ty, i_usize| { | 19499 | for (types, 0..) |field_ty, i_usize| { |
| 19426 | const i = @as(u32, @intCast(i_usize)); | 19500 | const i: u32 = @intCast(i_usize); |
| 19427 | const item = switch (kind) { | 19501 | const item = switch (kind) { |
| 19428 | .anon_init => sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index), | 19502 | .anon_init => sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index), |
| 19429 | .typed_init => sema.code.extraData(Zir.Inst.StructInit.Item, extra_index), | 19503 | .typed_init => sema.code.extraData(Zir.Inst.StructInit.Item, extra_index), |
| ... | @@ -19504,7 +19578,9 @@ fn zirArrayInit( | ... | @@ -19504,7 +19578,9 @@ fn zirArrayInit( |
| 19504 | const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse { | 19578 | const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse { |
| 19505 | const decl = mod.declPtr(block.src_decl); | 19579 | const decl = mod.declPtr(block.src_decl); |
| 19506 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | 19580 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); |
| 19507 | return sema.failWithNeededComptime(block, elem_src, "value stored in comptime field must be comptime-known"); | 19581 | return sema.failWithNeededComptime(block, elem_src, .{ |
| | 19582 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 19583 | }); |
| 19508 | }; | 19584 | }; |
| 19509 | if (!field_val.eql(init_val, elem_ty, mod)) { | 19585 | if (!field_val.eql(init_val, elem_ty, mod)) { |
| 19510 | const decl = mod.declPtr(block.src_decl); | 19586 | const decl = mod.declPtr(block.src_decl); |
| ... | @@ -19520,7 +19596,7 @@ fn zirArrayInit( | ... | @@ -19520,7 +19596,7 @@ fn zirArrayInit( |
| 19520 | | 19596 | |
| 19521 | const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| { | 19597 | const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| { |
| 19522 | const comptime_known = try sema.isComptimeKnown(arg); | 19598 | const comptime_known = try sema.isComptimeKnown(arg); |
| 19523 | if (!comptime_known) break @as(u32, @intCast(i)); | 19599 | if (!comptime_known) break @intCast(i); |
| 19524 | } else null; | 19600 | } else null; |
| 19525 | | 19601 | |
| 19526 | const runtime_index = opt_runtime_index orelse { | 19602 | const runtime_index = opt_runtime_index orelse { |
| ... | @@ -19629,7 +19705,7 @@ fn arrayInitAnon( | ... | @@ -19629,7 +19705,7 @@ fn arrayInitAnon( |
| 19629 | try sema.addDeclaredHereNote(msg, types[i].toType()); | 19705 | try sema.addDeclaredHereNote(msg, types[i].toType()); |
| 19630 | break :msg msg; | 19706 | break :msg msg; |
| 19631 | }; | 19707 | }; |
| 19632 | return sema.failWithOwnedErrorMsg(msg); | 19708 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19633 | } | 19709 | } |
| 19634 | if (try sema.resolveMaybeUndefVal(elem)) |val| { | 19710 | if (try sema.resolveMaybeUndefVal(elem)) |val| { |
| 19635 | values[i] = val.toIntern(); | 19711 | values[i] = val.toIntern(); |
| ... | @@ -19665,7 +19741,7 @@ fn arrayInitAnon( | ... | @@ -19665,7 +19741,7 @@ fn arrayInitAnon( |
| 19665 | }); | 19741 | }); |
| 19666 | const alloc = try block.addTy(.alloc, alloc_ty); | 19742 | const alloc = try block.addTy(.alloc, alloc_ty); |
| 19667 | for (operands, 0..) |operand, i_usize| { | 19743 | for (operands, 0..) |operand, i_usize| { |
| 19668 | const i = @as(u32, @intCast(i_usize)); | 19744 | const i: u32 = @intCast(i_usize); |
| 19669 | const field_ptr_ty = try mod.ptrType(.{ | 19745 | const field_ptr_ty = try mod.ptrType(.{ |
| 19670 | .child = types[i], | 19746 | .child = types[i], |
| 19671 | .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) }, | 19747 | .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) }, |
| ... | @@ -19712,7 +19788,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -19712,7 +19788,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 19712 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 19788 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 19713 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 19789 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 19714 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 19790 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 19715 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known"); | 19791 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| | 19792 | .needed_comptime_reason = "field name must be comptime-known", |
| | 19793 | }); |
| 19716 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); | 19794 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 19717 | } | 19795 | } |
| 19718 | | 19796 | |
| ... | @@ -19728,7 +19806,7 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -19728,7 +19806,7 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 19728 | // generic poison should not result in a failed compilation, but the | 19806 | // generic poison should not result in a failed compilation, but the |
| 19729 | // generic poison type. This prevents unnecessary failures when | 19807 | // generic poison type. This prevents unnecessary failures when |
| 19730 | // constructing types at compile-time. | 19808 | // constructing types at compile-time. |
| 19731 | error.GenericPoison => return Air.Inst.Ref.generic_poison_type, | 19809 | error.GenericPoison => return .generic_poison_type, |
| 19732 | else => |e| return e, | 19810 | else => |e| return e, |
| 19733 | }; | 19811 | }; |
| 19734 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); | 19812 | const zir_field_name = sema.code.nullTerminatedString(extra.name_start); |
| ... | @@ -19818,7 +19896,7 @@ fn zirFrame( | ... | @@ -19818,7 +19896,7 @@ fn zirFrame( |
| 19818 | block: *Block, | 19896 | block: *Block, |
| 19819 | extended: Zir.Inst.Extended.InstData, | 19897 | extended: Zir.Inst.Extended.InstData, |
| 19820 | ) CompileError!Air.Inst.Ref { | 19898 | ) CompileError!Air.Inst.Ref { |
| 19821 | const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand))); | 19899 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 19822 | return sema.failWithUseOfAsync(block, src); | 19900 | return sema.failWithUseOfAsync(block, src); |
| 19823 | } | 19901 | } |
| 19824 | | 19902 | |
| ... | @@ -19983,7 +20061,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19983,7 +20061,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19983 | try sema.resolveTypeLayout(operand_ty); | 20061 | try sema.resolveTypeLayout(operand_ty); |
| 19984 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { | 20062 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 19985 | .EnumLiteral => { | 20063 | .EnumLiteral => { |
| 19986 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); | 20064 | const val = try sema.resolveConstValue(block, .unneeded, operand, undefined); |
| 19987 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; | 20065 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 19988 | return sema.addStrLit(block, ip.stringToSlice(tag_name)); | 20066 | return sema.addStrLit(block, ip.stringToSlice(tag_name)); |
| 19989 | }, | 20067 | }, |
| ... | @@ -19997,7 +20075,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19997,7 +20075,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19997 | try sema.addDeclaredHereNote(msg, operand_ty); | 20075 | try sema.addDeclaredHereNote(msg, operand_ty); |
| 19998 | break :msg msg; | 20076 | break :msg msg; |
| 19999 | }; | 20077 | }; |
| 20000 | return sema.failWithOwnedErrorMsg(msg); | 20078 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20001 | }, | 20079 | }, |
| 20002 | else => return sema.fail(block, operand_src, "expected enum or union; found '{}'", .{ | 20080 | else => return sema.fail(block, operand_src, "expected enum or union; found '{}'", .{ |
| 20003 | operand_ty.fmt(mod), | 20081 | operand_ty.fmt(mod), |
| ... | @@ -20023,7 +20101,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20023,7 +20101,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20023 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); | 20101 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); |
| 20024 | break :msg msg; | 20102 | break :msg msg; |
| 20025 | }; | 20103 | }; |
| 20026 | return sema.failWithOwnedErrorMsg(msg); | 20104 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20027 | }; | 20105 | }; |
| 20028 | // TODO: write something like getCoercedInts to avoid needing to dupe | 20106 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 20029 | const field_name = enum_ty.enumFieldName(field_index, mod); | 20107 | const field_name = enum_ty.enumFieldName(field_index, mod); |
| ... | @@ -20049,29 +20127,31 @@ fn zirReify( | ... | @@ -20049,29 +20127,31 @@ fn zirReify( |
| 20049 | const mod = sema.mod; | 20127 | const mod = sema.mod; |
| 20050 | const gpa = sema.gpa; | 20128 | const gpa = sema.gpa; |
| 20051 | const ip = &mod.intern_pool; | 20129 | const ip = &mod.intern_pool; |
| 20052 | const name_strategy = @as(Zir.Inst.NameStrategy, @enumFromInt(extended.small)); | 20130 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 20053 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 20131 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 20054 | const src = LazySrcLoc.nodeOffset(extra.node); | 20132 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 20055 | const type_info_ty = try sema.getBuiltinType("Type"); | 20133 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 20056 | const uncasted_operand = try sema.resolveInst(extra.operand); | 20134 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 20057 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 20135 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 20058 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 20136 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 20059 | const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known"); | 20137 | const val = try sema.resolveConstValue(block, operand_src, type_info, .{ |
| | 20138 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| | 20139 | }); |
| 20060 | const union_val = ip.indexToKey(val.toIntern()).un; | 20140 | const union_val = ip.indexToKey(val.toIntern()).un; |
| 20061 | const target = mod.getTarget(); | 20141 | const target = mod.getTarget(); |
| 20062 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); | 20142 | if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src); |
| 20063 | const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?; | 20143 | const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?; |
| 20064 | switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) { | 20144 | switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) { |
| 20065 | .Type => return Air.Inst.Ref.type_type, | 20145 | .Type => return .type_type, |
| 20066 | .Void => return Air.Inst.Ref.void_type, | 20146 | .Void => return .void_type, |
| 20067 | .Bool => return Air.Inst.Ref.bool_type, | 20147 | .Bool => return .bool_type, |
| 20068 | .NoReturn => return Air.Inst.Ref.noreturn_type, | 20148 | .NoReturn => return .noreturn_type, |
| 20069 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, | 20149 | .ComptimeFloat => return .comptime_float_type, |
| 20070 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, | 20150 | .ComptimeInt => return .comptime_int_type, |
| 20071 | .Undefined => return Air.Inst.Ref.undefined_type, | 20151 | .Undefined => return .undefined_type, |
| 20072 | .Null => return Air.Inst.Ref.null_type, | 20152 | .Null => return .null_type, |
| 20073 | .AnyFrame => return sema.failWithUseOfAsync(block, src), | 20153 | .AnyFrame => return sema.failWithUseOfAsync(block, src), |
| 20074 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, | 20154 | .EnumLiteral => return .enum_literal_type, |
| 20075 | .Int => { | 20155 | .Int => { |
| 20076 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); | 20156 | const fields = ip.typeOf(union_val.val).toType().structFields(mod); |
| 20077 | const signedness_val = try union_val.val.toValue().fieldValue( | 20157 | const signedness_val = try union_val.val.toValue().fieldValue( |
| ... | @@ -20084,7 +20164,7 @@ fn zirReify( | ... | @@ -20084,7 +20164,7 @@ fn zirReify( |
| 20084 | ); | 20164 | ); |
| 20085 | | 20165 | |
| 20086 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); | 20166 | const signedness = mod.toEnum(std.builtin.Signedness, signedness_val); |
| 20087 | const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod))); | 20167 | const bits: u16 = @intCast(bits_val.toUnsignedInt(mod)); |
| 20088 | const ty = try mod.intType(signedness, bits); | 20168 | const ty = try mod.intType(signedness, bits); |
| 20089 | return Air.internedToRef(ty.toIntern()); | 20169 | return Air.internedToRef(ty.toIntern()); |
| 20090 | }, | 20170 | }, |
| ... | @@ -20097,7 +20177,7 @@ fn zirReify( | ... | @@ -20097,7 +20177,7 @@ fn zirReify( |
| 20097 | try ip.getOrPutString(gpa, "child"), | 20177 | try ip.getOrPutString(gpa, "child"), |
| 20098 | ).?); | 20178 | ).?); |
| 20099 | | 20179 | |
| 20100 | const len = @as(u32, @intCast(len_val.toUnsignedInt(mod))); | 20180 | const len: u32 = @intCast(len_val.toUnsignedInt(mod)); |
| 20101 | const child_ty = child_val.toType(); | 20181 | const child_ty = child_val.toType(); |
| 20102 | | 20182 | |
| 20103 | try sema.checkVectorElemType(block, src, child_ty); | 20183 | try sema.checkVectorElemType(block, src, child_ty); |
| ... | @@ -20114,7 +20194,7 @@ fn zirReify( | ... | @@ -20114,7 +20194,7 @@ fn zirReify( |
| 20114 | try ip.getOrPutString(gpa, "bits"), | 20194 | try ip.getOrPutString(gpa, "bits"), |
| 20115 | ).?); | 20195 | ).?); |
| 20116 | | 20196 | |
| 20117 | const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod))); | 20197 | const bits: u16 = @intCast(bits_val.toUnsignedInt(mod)); |
| 20118 | const ty = switch (bits) { | 20198 | const ty = switch (bits) { |
| 20119 | 16 => Type.f16, | 20199 | 16 => Type.f16, |
| 20120 | 32 => Type.f32, | 20200 | 32 => Type.f32, |
| ... | @@ -20206,7 +20286,7 @@ fn zirReify( | ... | @@ -20206,7 +20286,7 @@ fn zirReify( |
| 20206 | try sema.addDeclaredHereNote(msg, elem_ty); | 20286 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 20207 | break :msg msg; | 20287 | break :msg msg; |
| 20208 | }; | 20288 | }; |
| 20209 | return sema.failWithOwnedErrorMsg(msg); | 20289 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20210 | } | 20290 | } |
| 20211 | if (elem_ty.zigTypeTag(mod) == .Opaque) { | 20291 | if (elem_ty.zigTypeTag(mod) == .Opaque) { |
| 20212 | return sema.fail(block, src, "C pointers cannot point to opaque types", .{}); | 20292 | return sema.fail(block, src, "C pointers cannot point to opaque types", .{}); |
| ... | @@ -20382,7 +20462,7 @@ fn zirReify( | ... | @@ -20382,7 +20462,7 @@ fn zirReify( |
| 20382 | } | 20462 | } |
| 20383 | | 20463 | |
| 20384 | // Define our empty enum decl | 20464 | // Define our empty enum decl |
| 20385 | const fields_len = @as(u32, @intCast(try sema.usizeCast(block, src, fields_val.sliceLen(mod)))); | 20465 | const fields_len: u32 = @intCast(try sema.usizeCast(block, src, fields_val.sliceLen(mod))); |
| 20386 | const incomplete_enum = try ip.getIncompleteEnum(gpa, .{ | 20466 | const incomplete_enum = try ip.getIncompleteEnum(gpa, .{ |
| 20387 | .decl = new_decl_index, | 20467 | .decl = new_decl_index, |
| 20388 | .namespace = .none, | 20468 | .namespace = .none, |
| ... | @@ -20431,7 +20511,7 @@ fn zirReify( | ... | @@ -20431,7 +20511,7 @@ fn zirReify( |
| 20431 | try sema.errNote(block, src, msg, "other field here", .{}); | 20511 | try sema.errNote(block, src, msg, "other field here", .{}); |
| 20432 | break :msg msg; | 20512 | break :msg msg; |
| 20433 | }; | 20513 | }; |
| 20434 | return sema.failWithOwnedErrorMsg(msg); | 20514 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20435 | } | 20515 | } |
| 20436 | | 20516 | |
| 20437 | if (try incomplete_enum.addFieldValue(ip, gpa, (try mod.getCoerced(value_val, int_tag_ty)).toIntern())) |other| { | 20517 | if (try incomplete_enum.addFieldValue(ip, gpa, (try mod.getCoerced(value_val, int_tag_ty)).toIntern())) |other| { |
| ... | @@ -20442,7 +20522,7 @@ fn zirReify( | ... | @@ -20442,7 +20522,7 @@ fn zirReify( |
| 20442 | try sema.errNote(block, src, msg, "other enum tag value here", .{}); | 20522 | try sema.errNote(block, src, msg, "other enum tag value here", .{}); |
| 20443 | break :msg msg; | 20523 | break :msg msg; |
| 20444 | }; | 20524 | }; |
| 20445 | return sema.failWithOwnedErrorMsg(msg); | 20525 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20446 | } | 20526 | } |
| 20447 | } | 20527 | } |
| 20448 | | 20528 | |
| ... | @@ -20579,7 +20659,7 @@ fn zirReify( | ... | @@ -20579,7 +20659,7 @@ fn zirReify( |
| 20579 | try sema.addDeclaredHereNote(msg, enum_tag_ty.toType()); | 20659 | try sema.addDeclaredHereNote(msg, enum_tag_ty.toType()); |
| 20580 | break :msg msg; | 20660 | break :msg msg; |
| 20581 | }; | 20661 | }; |
| 20582 | return sema.failWithOwnedErrorMsg(msg); | 20662 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20583 | }; | 20663 | }; |
| 20584 | // No check for duplicate because the check already happened in order | 20664 | // No check for duplicate because the check already happened in order |
| 20585 | // to create the enum type in the first place. | 20665 | // to create the enum type in the first place. |
| ... | @@ -20610,7 +20690,7 @@ fn zirReify( | ... | @@ -20610,7 +20690,7 @@ fn zirReify( |
| 20610 | try sema.addDeclaredHereNote(msg, field_ty); | 20690 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20611 | break :msg msg; | 20691 | break :msg msg; |
| 20612 | }; | 20692 | }; |
| 20613 | return sema.failWithOwnedErrorMsg(msg); | 20693 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20614 | } | 20694 | } |
| 20615 | if (layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { | 20695 | if (layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { |
| 20616 | const msg = msg: { | 20696 | const msg = msg: { |
| ... | @@ -20623,7 +20703,7 @@ fn zirReify( | ... | @@ -20623,7 +20703,7 @@ fn zirReify( |
| 20623 | try sema.addDeclaredHereNote(msg, field_ty); | 20703 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20624 | break :msg msg; | 20704 | break :msg msg; |
| 20625 | }; | 20705 | }; |
| 20626 | return sema.failWithOwnedErrorMsg(msg); | 20706 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20627 | } else if (layout == .Packed and !(validatePackedType(field_ty, mod))) { | 20707 | } else if (layout == .Packed and !(validatePackedType(field_ty, mod))) { |
| 20628 | const msg = msg: { | 20708 | const msg = msg: { |
| 20629 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 20709 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| ... | @@ -20635,7 +20715,7 @@ fn zirReify( | ... | @@ -20635,7 +20715,7 @@ fn zirReify( |
| 20635 | try sema.addDeclaredHereNote(msg, field_ty); | 20715 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20636 | break :msg msg; | 20716 | break :msg msg; |
| 20637 | }; | 20717 | }; |
| 20638 | return sema.failWithOwnedErrorMsg(msg); | 20718 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20639 | } | 20719 | } |
| 20640 | } | 20720 | } |
| 20641 | | 20721 | |
| ... | @@ -20655,7 +20735,7 @@ fn zirReify( | ... | @@ -20655,7 +20735,7 @@ fn zirReify( |
| 20655 | try sema.addDeclaredHereNote(msg, enum_tag_ty.toType()); | 20735 | try sema.addDeclaredHereNote(msg, enum_tag_ty.toType()); |
| 20656 | break :msg msg; | 20736 | break :msg msg; |
| 20657 | }; | 20737 | }; |
| 20658 | return sema.failWithOwnedErrorMsg(msg); | 20738 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20659 | } | 20739 | } |
| 20660 | } else { | 20740 | } else { |
| 20661 | enum_tag_ty = try sema.generateUnionTagTypeSimple(block, enum_field_names, .none); | 20741 | enum_tag_ty = try sema.generateUnionTagTypeSimple(block, enum_field_names, .none); |
| ... | @@ -20753,7 +20833,7 @@ fn zirReify( | ... | @@ -20753,7 +20833,7 @@ fn zirReify( |
| 20753 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { | 20833 | if (!try sema.intFitsInType(alignment_val, Type.u32, null)) { |
| 20754 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); | 20834 | return sema.fail(block, src, "alignment must fit in 'u32'", .{}); |
| 20755 | } | 20835 | } |
| 20756 | const alignment = @as(u29, @intCast(alignment_val.toUnsignedInt(mod))); | 20836 | const alignment: u29 = @intCast(alignment_val.toUnsignedInt(mod)); |
| 20757 | if (alignment == target_util.defaultFunctionAlignment(target)) { | 20837 | if (alignment == target_util.defaultFunctionAlignment(target)) { |
| 20758 | break :alignment .none; | 20838 | break :alignment .none; |
| 20759 | } else { | 20839 | } else { |
| ... | @@ -20948,7 +21028,9 @@ fn reifyStruct( | ... | @@ -20948,7 +21028,9 @@ fn reifyStruct( |
| 20948 | const field_ty = type_val.toType(); | 21028 | const field_ty = type_val.toType(); |
| 20949 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| | 21029 | const default_val = if (default_value_val.optionalValue(mod)) |opt_val| |
| 20950 | (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse | 21030 | (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse |
| 20951 | return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern() | 21031 | return sema.failWithNeededComptime(block, src, .{ |
| | 21032 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| | 21033 | })).toIntern() |
| 20952 | else | 21034 | else |
| 20953 | .none; | 21035 | .none; |
| 20954 | if (is_comptime_val.toBool() and default_val == .none) { | 21036 | if (is_comptime_val.toBool() and default_val == .none) { |
| ... | @@ -20971,7 +21053,7 @@ fn reifyStruct( | ... | @@ -20971,7 +21053,7 @@ fn reifyStruct( |
| 20971 | try sema.addDeclaredHereNote(msg, field_ty); | 21053 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20972 | break :msg msg; | 21054 | break :msg msg; |
| 20973 | }; | 21055 | }; |
| 20974 | return sema.failWithOwnedErrorMsg(msg); | 21056 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20975 | } | 21057 | } |
| 20976 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 21058 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 20977 | const msg = msg: { | 21059 | const msg = msg: { |
| ... | @@ -20981,7 +21063,7 @@ fn reifyStruct( | ... | @@ -20981,7 +21063,7 @@ fn reifyStruct( |
| 20981 | try sema.addDeclaredHereNote(msg, field_ty); | 21063 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20982 | break :msg msg; | 21064 | break :msg msg; |
| 20983 | }; | 21065 | }; |
| 20984 | return sema.failWithOwnedErrorMsg(msg); | 21066 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20985 | } | 21067 | } |
| 20986 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) { | 21068 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) { |
| 20987 | const msg = msg: { | 21069 | const msg = msg: { |
| ... | @@ -20994,7 +21076,7 @@ fn reifyStruct( | ... | @@ -20994,7 +21076,7 @@ fn reifyStruct( |
| 20994 | try sema.addDeclaredHereNote(msg, field_ty); | 21076 | try sema.addDeclaredHereNote(msg, field_ty); |
| 20995 | break :msg msg; | 21077 | break :msg msg; |
| 20996 | }; | 21078 | }; |
| 20997 | return sema.failWithOwnedErrorMsg(msg); | 21079 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20998 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) { | 21080 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) { |
| 20999 | const msg = msg: { | 21081 | const msg = msg: { |
| 21000 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | 21082 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| ... | @@ -21006,7 +21088,7 @@ fn reifyStruct( | ... | @@ -21006,7 +21088,7 @@ fn reifyStruct( |
| 21006 | try sema.addDeclaredHereNote(msg, field_ty); | 21088 | try sema.addDeclaredHereNote(msg, field_ty); |
| 21007 | break :msg msg; | 21089 | break :msg msg; |
| 21008 | }; | 21090 | }; |
| 21009 | return sema.failWithOwnedErrorMsg(msg); | 21091 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21010 | } | 21092 | } |
| 21011 | } | 21093 | } |
| 21012 | | 21094 | |
| ... | @@ -21034,7 +21116,7 @@ fn reifyStruct( | ... | @@ -21034,7 +21116,7 @@ fn reifyStruct( |
| 21034 | try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum); | 21116 | try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum); |
| 21035 | struct_obj.backing_int_ty = backing_int_ty; | 21117 | struct_obj.backing_int_ty = backing_int_ty; |
| 21036 | } else { | 21118 | } else { |
| 21037 | struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum))); | 21119 | struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); |
| 21038 | } | 21120 | } |
| 21039 | | 21121 | |
| 21040 | struct_obj.status = .have_layout; | 21122 | struct_obj.status = .have_layout; |
| ... | @@ -21074,7 +21156,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -21074,7 +21156,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21074 | try sema.addDeclaredHereNote(msg, arg_ty); | 21156 | try sema.addDeclaredHereNote(msg, arg_ty); |
| 21075 | break :msg msg; | 21157 | break :msg msg; |
| 21076 | }; | 21158 | }; |
| 21077 | return sema.failWithOwnedErrorMsg(msg); | 21159 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21078 | } | 21160 | } |
| 21079 | | 21161 | |
| 21080 | try sema.requireRuntimeBlock(block, src, null); | 21162 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -21105,7 +21187,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -21105,7 +21187,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 21105 | } | 21187 | } |
| 21106 | | 21188 | |
| 21107 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 21189 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 21108 | const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand))); | 21190 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 21109 | | 21191 | |
| 21110 | const va_list_ty = try sema.getBuiltinType("VaList"); | 21192 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 21111 | try sema.requireRuntimeBlock(block, src, null); | 21193 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -21180,7 +21262,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -21180,7 +21262,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21180 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty); | 21262 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty); |
| 21181 | return Air.internedToRef(result_val.toIntern()); | 21263 | return Air.internedToRef(result_val.toIntern()); |
| 21182 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) { | 21264 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 21183 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known"); | 21265 | return sema.failWithNeededComptime(block, operand_src, .{ |
| | 21266 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 21267 | }); |
| 21184 | } | 21268 | } |
| 21185 | | 21269 | |
| 21186 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 21270 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| ... | @@ -21260,7 +21344,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -21260,7 +21344,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21260 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema); | 21344 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema); |
| 21261 | return Air.internedToRef(result_val.toIntern()); | 21345 | return Air.internedToRef(result_val.toIntern()); |
| 21262 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) { | 21346 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 21263 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known"); | 21347 | return sema.failWithNeededComptime(block, operand_src, .{ |
| | 21348 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 21349 | }); |
| 21264 | } | 21350 | } |
| 21265 | | 21351 | |
| 21266 | try sema.requireRuntimeBlock(block, src, operand_src); | 21352 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -21311,7 +21397,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -21311,7 +21397,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 21311 | try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{}); | 21397 | try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{}); |
| 21312 | break :msg msg; | 21398 | break :msg msg; |
| 21313 | }; | 21399 | }; |
| 21314 | return sema.failWithOwnedErrorMsg(msg); | 21400 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21315 | } | 21401 | } |
| 21316 | | 21402 | |
| 21317 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { | 21403 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| ... | @@ -21447,7 +21533,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -21447,7 +21533,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 21447 | try sema.addDeclaredHereNote(msg, dest_ty); | 21533 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 21448 | break :msg msg; | 21534 | break :msg msg; |
| 21449 | }; | 21535 | }; |
| 21450 | return sema.failWithOwnedErrorMsg(msg); | 21536 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21451 | } | 21537 | } |
| 21452 | | 21538 | |
| 21453 | if (maybe_operand_val) |val| { | 21539 | if (maybe_operand_val) |val| { |
| ... | @@ -21465,7 +21551,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -21465,7 +21551,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 21465 | try sema.addDeclaredHereNote(msg, dest_ty); | 21551 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 21466 | break :msg msg; | 21552 | break :msg msg; |
| 21467 | }; | 21553 | }; |
| 21468 | return sema.failWithOwnedErrorMsg(msg); | 21554 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21469 | } | 21555 | } |
| 21470 | } | 21556 | } |
| 21471 | | 21557 | |
| ... | @@ -21482,7 +21568,10 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -21482,7 +21568,10 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 21482 | } | 21568 | } |
| 21483 | | 21569 | |
| 21484 | fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 21570 | fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 21485 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(u5, @truncate(extended.small))); | 21571 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as( |
| | 21572 | @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?, |
| | 21573 | @truncate(extended.small), |
| | 21574 | )); |
| 21486 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 21575 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 21487 | const src = LazySrcLoc.nodeOffset(extra.node); | 21576 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 21488 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 21577 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; |
| ... | @@ -21568,7 +21657,7 @@ fn ptrCastFull( | ... | @@ -21568,7 +21657,7 @@ fn ptrCastFull( |
| 21568 | if (src_slice_like and dest_slice_like) break :check_size; | 21657 | if (src_slice_like and dest_slice_like) break :check_size; |
| 21569 | if (src_info.flags.size == .C) break :check_size; | 21658 | if (src_info.flags.size == .C) break :check_size; |
| 21570 | if (dest_info.flags.size == .C) break :check_size; | 21659 | if (dest_info.flags.size == .C) break :check_size; |
| 21571 | return sema.failWithOwnedErrorMsg(msg: { | 21660 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21572 | const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{ | 21661 | const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{ |
| 21573 | pointerSizeString(src_info.flags.size), | 21662 | pointerSizeString(src_info.flags.size), |
| 21574 | pointerSizeString(dest_info.flags.size), | 21663 | pointerSizeString(dest_info.flags.size), |
| ... | @@ -21604,7 +21693,7 @@ fn ptrCastFull( | ... | @@ -21604,7 +21693,7 @@ fn ptrCastFull( |
| 21604 | operand_src, | 21693 | operand_src, |
| 21605 | ); | 21694 | ); |
| 21606 | if (imc_res == .ok) break :check_child; | 21695 | if (imc_res == .ok) break :check_child; |
| 21607 | return sema.failWithOwnedErrorMsg(msg: { | 21696 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21608 | const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{ | 21697 | const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{ |
| 21609 | src_child.fmt(mod), | 21698 | src_child.fmt(mod), |
| 21610 | dest_child.fmt(mod), | 21699 | dest_child.fmt(mod), |
| ... | @@ -21631,7 +21720,7 @@ fn ptrCastFull( | ... | @@ -21631,7 +21720,7 @@ fn ptrCastFull( |
| 21631 | if (dest_info.sentinel == coerced_sent) break :check_sent; | 21720 | if (dest_info.sentinel == coerced_sent) break :check_sent; |
| 21632 | } | 21721 | } |
| 21633 | } | 21722 | } |
| 21634 | return sema.failWithOwnedErrorMsg(msg: { | 21723 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21635 | const msg = if (src_info.sentinel == .none) blk: { | 21724 | const msg = if (src_info.sentinel == .none) blk: { |
| 21636 | break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{ | 21725 | break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{ |
| 21637 | dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod), | 21726 | dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod), |
| ... | @@ -21649,7 +21738,7 @@ fn ptrCastFull( | ... | @@ -21649,7 +21738,7 @@ fn ptrCastFull( |
| 21649 | } | 21738 | } |
| 21650 | | 21739 | |
| 21651 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { | 21740 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { |
| 21652 | return sema.failWithOwnedErrorMsg(msg: { | 21741 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21653 | const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ | 21742 | const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ |
| 21654 | src_info.packed_offset.host_size, | 21743 | src_info.packed_offset.host_size, |
| 21655 | dest_info.packed_offset.host_size, | 21744 | dest_info.packed_offset.host_size, |
| ... | @@ -21661,7 +21750,7 @@ fn ptrCastFull( | ... | @@ -21661,7 +21750,7 @@ fn ptrCastFull( |
| 21661 | } | 21750 | } |
| 21662 | | 21751 | |
| 21663 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { | 21752 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { |
| 21664 | return sema.failWithOwnedErrorMsg(msg: { | 21753 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21665 | const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ | 21754 | const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ |
| 21666 | src_info.packed_offset.bit_offset, | 21755 | src_info.packed_offset.bit_offset, |
| 21667 | dest_info.packed_offset.bit_offset, | 21756 | dest_info.packed_offset.bit_offset, |
| ... | @@ -21678,7 +21767,7 @@ fn ptrCastFull( | ... | @@ -21678,7 +21767,7 @@ fn ptrCastFull( |
| 21678 | if (!src_allows_zero) break :check_allowzero; | 21767 | if (!src_allows_zero) break :check_allowzero; |
| 21679 | if (dest_allows_zero) break :check_allowzero; | 21768 | if (dest_allows_zero) break :check_allowzero; |
| 21680 | | 21769 | |
| 21681 | return sema.failWithOwnedErrorMsg(msg: { | 21770 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21682 | const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{ | 21771 | const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{ |
| 21683 | operand_ty.fmt(mod), | 21772 | operand_ty.fmt(mod), |
| 21684 | dest_ty.fmt(mod), | 21773 | dest_ty.fmt(mod), |
| ... | @@ -21696,7 +21785,7 @@ fn ptrCastFull( | ... | @@ -21696,7 +21785,7 @@ fn ptrCastFull( |
| 21696 | const dest_align = dest_info.flags.alignment.toByteUnitsOptional() orelse dest_info.child.toType().abiAlignment(mod); | 21785 | const dest_align = dest_info.flags.alignment.toByteUnitsOptional() orelse dest_info.child.toType().abiAlignment(mod); |
| 21697 | if (!flags.align_cast) { | 21786 | if (!flags.align_cast) { |
| 21698 | if (dest_align > src_align) { | 21787 | if (dest_align > src_align) { |
| 21699 | return sema.failWithOwnedErrorMsg(msg: { | 21788 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21700 | const msg = try sema.errMsg(block, src, "cast increases pointer alignment", .{}); | 21789 | const msg = try sema.errMsg(block, src, "cast increases pointer alignment", .{}); |
| 21701 | errdefer msg.destroy(sema.gpa); | 21790 | errdefer msg.destroy(sema.gpa); |
| 21702 | try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{ | 21791 | try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{ |
| ... | @@ -21713,7 +21802,7 @@ fn ptrCastFull( | ... | @@ -21713,7 +21802,7 @@ fn ptrCastFull( |
| 21713 | | 21802 | |
| 21714 | if (!flags.addrspace_cast) { | 21803 | if (!flags.addrspace_cast) { |
| 21715 | if (src_info.flags.address_space != dest_info.flags.address_space) { | 21804 | if (src_info.flags.address_space != dest_info.flags.address_space) { |
| 21716 | return sema.failWithOwnedErrorMsg(msg: { | 21805 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21717 | const msg = try sema.errMsg(block, src, "cast changes pointer address space", .{}); | 21806 | const msg = try sema.errMsg(block, src, "cast changes pointer address space", .{}); |
| 21718 | errdefer msg.destroy(sema.gpa); | 21807 | errdefer msg.destroy(sema.gpa); |
| 21719 | try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{ | 21808 | try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{ |
| ... | @@ -21729,7 +21818,7 @@ fn ptrCastFull( | ... | @@ -21729,7 +21818,7 @@ fn ptrCastFull( |
| 21729 | } else { | 21818 | } else { |
| 21730 | // Some address space casts are always disallowed | 21819 | // Some address space casts are always disallowed |
| 21731 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { | 21820 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { |
| 21732 | return sema.failWithOwnedErrorMsg(msg: { | 21821 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21733 | const msg = try sema.errMsg(block, src, "invalid address space cast", .{}); | 21822 | const msg = try sema.errMsg(block, src, "invalid address space cast", .{}); |
| 21734 | errdefer msg.destroy(sema.gpa); | 21823 | errdefer msg.destroy(sema.gpa); |
| 21735 | try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ | 21824 | try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ |
| ... | @@ -21743,7 +21832,7 @@ fn ptrCastFull( | ... | @@ -21743,7 +21832,7 @@ fn ptrCastFull( |
| 21743 | | 21832 | |
| 21744 | if (!flags.const_cast) { | 21833 | if (!flags.const_cast) { |
| 21745 | if (src_info.flags.is_const and !dest_info.flags.is_const) { | 21834 | if (src_info.flags.is_const and !dest_info.flags.is_const) { |
| 21746 | return sema.failWithOwnedErrorMsg(msg: { | 21835 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21747 | const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{}); | 21836 | const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{}); |
| 21748 | errdefer msg.destroy(sema.gpa); | 21837 | errdefer msg.destroy(sema.gpa); |
| 21749 | try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{}); | 21838 | try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{}); |
| ... | @@ -21754,7 +21843,7 @@ fn ptrCastFull( | ... | @@ -21754,7 +21843,7 @@ fn ptrCastFull( |
| 21754 | | 21843 | |
| 21755 | if (!flags.volatile_cast) { | 21844 | if (!flags.volatile_cast) { |
| 21756 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { | 21845 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { |
| 21757 | return sema.failWithOwnedErrorMsg(msg: { | 21846 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 21758 | const msg = try sema.errMsg(block, src, "cast discards volatile qualifier", .{}); | 21847 | const msg = try sema.errMsg(block, src, "cast discards volatile qualifier", .{}); |
| 21759 | errdefer msg.destroy(sema.gpa); | 21848 | errdefer msg.destroy(sema.gpa); |
| 21760 | try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{}); | 21849 | try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{}); |
| ... | @@ -21885,7 +21974,10 @@ fn ptrCastFull( | ... | @@ -21885,7 +21974,10 @@ fn ptrCastFull( |
| 21885 | | 21974 | |
| 21886 | fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 21975 | fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 21887 | const mod = sema.mod; | 21976 | const mod = sema.mod; |
| 21888 | const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small)))); | 21977 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as( |
| | 21978 | @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?, |
| | 21979 | @truncate(extended.small), |
| | 21980 | )); |
| 21889 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 21981 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 21890 | const src = LazySrcLoc.nodeOffset(extra.node); | 21982 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 21891 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 21983 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; |
| ... | @@ -21962,7 +22054,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -21962,7 +22054,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21962 | }); | 22054 | }); |
| 21963 | break :msg msg; | 22055 | break :msg msg; |
| 21964 | }; | 22056 | }; |
| 21965 | return sema.failWithOwnedErrorMsg(msg); | 22057 | return sema.failWithOwnedErrorMsg(block, msg); |
| 21966 | } | 22058 | } |
| 21967 | } | 22059 | } |
| 21968 | | 22060 | |
| ... | @@ -22174,7 +22266,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -22174,7 +22266,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 22174 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22266 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22175 | | 22267 | |
| 22176 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 22268 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| 22177 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known"); | 22269 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| | 22270 | .needed_comptime_reason = "name of field must be comptime-known", |
| | 22271 | }); |
| 22178 | | 22272 | |
| 22179 | const mod = sema.mod; | 22273 | const mod = sema.mod; |
| 22180 | try sema.resolveTypeLayout(ty); | 22274 | try sema.resolveTypeLayout(ty); |
| ... | @@ -22187,7 +22281,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -22187,7 +22281,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 22187 | try sema.addDeclaredHereNote(msg, ty); | 22281 | try sema.addDeclaredHereNote(msg, ty); |
| 22188 | break :msg msg; | 22282 | break :msg msg; |
| 22189 | }; | 22283 | }; |
| 22190 | return sema.failWithOwnedErrorMsg(msg); | 22284 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22191 | }, | 22285 | }, |
| 22192 | } | 22286 | } |
| 22193 | | 22287 | |
| ... | @@ -22298,7 +22392,7 @@ fn checkPtrOperand( | ... | @@ -22298,7 +22392,7 @@ fn checkPtrOperand( |
| 22298 | | 22392 | |
| 22299 | break :msg msg; | 22393 | break :msg msg; |
| 22300 | }; | 22394 | }; |
| 22301 | return sema.failWithOwnedErrorMsg(msg); | 22395 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22302 | }, | 22396 | }, |
| 22303 | .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return, | 22397 | .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return, |
| 22304 | else => {}, | 22398 | else => {}, |
| ... | @@ -22329,7 +22423,7 @@ fn checkPtrType( | ... | @@ -22329,7 +22423,7 @@ fn checkPtrType( |
| 22329 | | 22423 | |
| 22330 | break :msg msg; | 22424 | break :msg msg; |
| 22331 | }; | 22425 | }; |
| 22332 | return sema.failWithOwnedErrorMsg(msg); | 22426 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22333 | }, | 22427 | }, |
| 22334 | .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return, | 22428 | .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return, |
| 22335 | else => {}, | 22429 | else => {}, |
| ... | @@ -22470,7 +22564,7 @@ fn checkComptimeVarStore( | ... | @@ -22470,7 +22564,7 @@ fn checkComptimeVarStore( |
| 22470 | try sema.errNote(block, cond_src, msg, "runtime condition here", .{}); | 22564 | try sema.errNote(block, cond_src, msg, "runtime condition here", .{}); |
| 22471 | break :msg msg; | 22565 | break :msg msg; |
| 22472 | }; | 22566 | }; |
| 22473 | return sema.failWithOwnedErrorMsg(msg); | 22567 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22474 | } | 22568 | } |
| 22475 | if (block.runtime_loop) |loop_src| { | 22569 | if (block.runtime_loop) |loop_src| { |
| 22476 | const msg = msg: { | 22570 | const msg = msg: { |
| ... | @@ -22479,7 +22573,7 @@ fn checkComptimeVarStore( | ... | @@ -22479,7 +22573,7 @@ fn checkComptimeVarStore( |
| 22479 | try sema.errNote(block, loop_src, msg, "non-inline loop here", .{}); | 22573 | try sema.errNote(block, loop_src, msg, "non-inline loop here", .{}); |
| 22480 | break :msg msg; | 22574 | break :msg msg; |
| 22481 | }; | 22575 | }; |
| 22482 | return sema.failWithOwnedErrorMsg(msg); | 22576 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22483 | } | 22577 | } |
| 22484 | unreachable; | 22578 | unreachable; |
| 22485 | } | 22579 | } |
| ... | @@ -22621,7 +22715,7 @@ fn checkVectorizableBinaryOperands( | ... | @@ -22621,7 +22715,7 @@ fn checkVectorizableBinaryOperands( |
| 22621 | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); | 22715 | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); |
| 22622 | break :msg msg; | 22716 | break :msg msg; |
| 22623 | }; | 22717 | }; |
| 22624 | return sema.failWithOwnedErrorMsg(msg); | 22718 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22625 | } | 22719 | } |
| 22626 | } else { | 22720 | } else { |
| 22627 | const msg = msg: { | 22721 | const msg = msg: { |
| ... | @@ -22638,7 +22732,7 @@ fn checkVectorizableBinaryOperands( | ... | @@ -22638,7 +22732,7 @@ fn checkVectorizableBinaryOperands( |
| 22638 | } | 22732 | } |
| 22639 | break :msg msg; | 22733 | break :msg msg; |
| 22640 | }; | 22734 | }; |
| 22641 | return sema.failWithOwnedErrorMsg(msg); | 22735 | return sema.failWithOwnedErrorMsg(block, msg); |
| 22642 | } | 22736 | } |
| 22643 | } | 22737 | } |
| 22644 | | 22738 | |
| ... | @@ -22667,16 +22761,22 @@ fn resolveExportOptions( | ... | @@ -22667,16 +22761,22 @@ fn resolveExportOptions( |
| 22667 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); | 22761 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 22668 | | 22762 | |
| 22669 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | 22763 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 22670 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known"); | 22764 | const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{ |
| | 22765 | .needed_comptime_reason = "name of exported value must be comptime-known", |
| | 22766 | }); |
| 22671 | const name_ty = Type.slice_const_u8; | 22767 | const name_ty = Type.slice_const_u8; |
| 22672 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); | 22768 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); |
| 22673 | | 22769 | |
| 22674 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | 22770 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 22675 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known"); | 22771 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{ |
| | 22772 | .needed_comptime_reason = "linkage of exported value must be comptime-known", |
| | 22773 | }); |
| 22676 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 22774 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 22677 | | 22775 | |
| 22678 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); | 22776 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); |
| 22679 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known"); | 22777 | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{ |
| | 22778 | .needed_comptime_reason = "linksection of exported value must be comptime-known", |
| | 22779 | }); |
| 22680 | const section_ty = Type.slice_const_u8; | 22780 | const section_ty = Type.slice_const_u8; |
| 22681 | const section = if (section_opt_val.optionalValue(mod)) |section_val| | 22781 | const section = if (section_opt_val.optionalValue(mod)) |section_val| |
| 22682 | try section_val.toAllocatedBytes(section_ty, sema.arena, mod) | 22782 | try section_val.toAllocatedBytes(section_ty, sema.arena, mod) |
| ... | @@ -22684,7 +22784,9 @@ fn resolveExportOptions( | ... | @@ -22684,7 +22784,9 @@ fn resolveExportOptions( |
| 22684 | null; | 22784 | null; |
| 22685 | | 22785 | |
| 22686 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); | 22786 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); |
| 22687 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known"); | 22787 | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{ |
| | 22788 | .needed_comptime_reason = "visibility of exported value must be comptime-known", |
| | 22789 | }); |
| 22688 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); | 22790 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| 22689 | | 22791 | |
| 22690 | if (name.len < 1) { | 22792 | if (name.len < 1) { |
| ... | @@ -22711,7 +22813,7 @@ fn resolveBuiltinEnum( | ... | @@ -22711,7 +22813,7 @@ fn resolveBuiltinEnum( |
| 22711 | src: LazySrcLoc, | 22813 | src: LazySrcLoc, |
| 22712 | zir_ref: Zir.Inst.Ref, | 22814 | zir_ref: Zir.Inst.Ref, |
| 22713 | comptime name: []const u8, | 22815 | comptime name: []const u8, |
| 22714 | reason: []const u8, | 22816 | reason: NeededComptimeReason, |
| 22715 | ) CompileError!@field(std.builtin, name) { | 22817 | ) CompileError!@field(std.builtin, name) { |
| 22716 | const mod = sema.mod; | 22818 | const mod = sema.mod; |
| 22717 | const ty = try sema.getBuiltinType(name); | 22819 | const ty = try sema.getBuiltinType(name); |
| ... | @@ -22726,7 +22828,7 @@ fn resolveAtomicOrder( | ... | @@ -22726,7 +22828,7 @@ fn resolveAtomicOrder( |
| 22726 | block: *Block, | 22828 | block: *Block, |
| 22727 | src: LazySrcLoc, | 22829 | src: LazySrcLoc, |
| 22728 | zir_ref: Zir.Inst.Ref, | 22830 | zir_ref: Zir.Inst.Ref, |
| 22729 | reason: []const u8, | 22831 | reason: NeededComptimeReason, |
| 22730 | ) CompileError!std.builtin.AtomicOrder { | 22832 | ) CompileError!std.builtin.AtomicOrder { |
| 22731 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); | 22833 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); |
| 22732 | } | 22834 | } |
| ... | @@ -22737,7 +22839,9 @@ fn resolveAtomicRmwOp( | ... | @@ -22737,7 +22839,9 @@ fn resolveAtomicRmwOp( |
| 22737 | src: LazySrcLoc, | 22839 | src: LazySrcLoc, |
| 22738 | zir_ref: Zir.Inst.Ref, | 22840 | zir_ref: Zir.Inst.Ref, |
| 22739 | ) CompileError!std.builtin.AtomicRmwOp { | 22841 | ) CompileError!std.builtin.AtomicRmwOp { |
| 22740 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known"); | 22842 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{ |
| | 22843 | .needed_comptime_reason = "@atomicRmW operation must be comptime-known", |
| | 22844 | }); |
| 22741 | } | 22845 | } |
| 22742 | | 22846 | |
| 22743 | fn zirCmpxchg( | 22847 | fn zirCmpxchg( |
| ... | @@ -22774,8 +22878,12 @@ fn zirCmpxchg( | ... | @@ -22774,8 +22878,12 @@ fn zirCmpxchg( |
| 22774 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 22878 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 22775 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 22879 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 22776 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); | 22880 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); |
| 22777 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, "atomic order of cmpxchg success must be comptime-known"); | 22881 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{ |
| 22778 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, "atomic order of cmpxchg failure must be comptime-known"); | 22882 | .needed_comptime_reason = "atomic order of cmpxchg success must be comptime-known", |
| | 22883 | }); |
| | 22884 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{ |
| | 22885 | .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known", |
| | 22886 | }); |
| 22779 | | 22887 | |
| 22780 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) { | 22888 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) { |
| 22781 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); | 22889 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| ... | @@ -22867,7 +22975,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -22867,7 +22975,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22867 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22975 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22868 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22976 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 22869 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 22977 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 22870 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", "@reduce operation must be comptime-known"); | 22978 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ |
| | 22979 | .needed_comptime_reason = "@reduce operation must be comptime-known", |
| | 22980 | }); |
| 22871 | const operand = try sema.resolveInst(extra.rhs); | 22981 | const operand = try sema.resolveInst(extra.rhs); |
| 22872 | const operand_ty = sema.typeOf(operand); | 22982 | const operand_ty = sema.typeOf(operand); |
| 22873 | const mod = sema.mod; | 22983 | const mod = sema.mod; |
| ... | @@ -22950,12 +23060,14 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -22950,12 +23060,14 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 22950 | else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}), | 23060 | else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}), |
| 22951 | }; | 23061 | }; |
| 22952 | mask_ty = try mod.vectorType(.{ | 23062 | mask_ty = try mod.vectorType(.{ |
| 22953 | .len = @as(u32, @intCast(mask_len)), | 23063 | .len = @intCast(mask_len), |
| 22954 | .child = .i32_type, | 23064 | .child = .i32_type, |
| 22955 | }); | 23065 | }); |
| 22956 | mask = try sema.coerce(block, mask_ty, mask, mask_src); | 23066 | mask = try sema.coerce(block, mask_ty, mask, mask_src); |
| 22957 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known"); | 23067 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{ |
| 22958 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @as(u32, @intCast(mask_len))); | 23068 | .needed_comptime_reason = "shuffle mask must be comptime-known", |
| | 23069 | }); |
| | 23070 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); |
| 22959 | } | 23071 | } |
| 22960 | | 23072 | |
| 22961 | fn analyzeShuffle( | 23073 | fn analyzeShuffle( |
| ... | @@ -22999,8 +23111,8 @@ fn analyzeShuffle( | ... | @@ -22999,8 +23111,8 @@ fn analyzeShuffle( |
| 22999 | if (maybe_a_len == null and maybe_b_len == null) { | 23111 | if (maybe_a_len == null and maybe_b_len == null) { |
| 23000 | return mod.undefRef(res_ty); | 23112 | return mod.undefRef(res_ty); |
| 23001 | } | 23113 | } |
| 23002 | const a_len = @as(u32, @intCast(maybe_a_len orelse maybe_b_len.?)); | 23114 | const a_len: u32 = @intCast(maybe_a_len orelse maybe_b_len.?); |
| 23003 | const b_len = @as(u32, @intCast(maybe_b_len orelse a_len)); | 23115 | const b_len: u32 = @intCast(maybe_b_len orelse a_len); |
| 23004 | | 23116 | |
| 23005 | const a_ty = try mod.vectorType(.{ | 23117 | const a_ty = try mod.vectorType(.{ |
| 23006 | .len = a_len, | 23118 | .len = a_len, |
| ... | @@ -23019,17 +23131,17 @@ fn analyzeShuffle( | ... | @@ -23019,17 +23131,17 @@ fn analyzeShuffle( |
| 23019 | .{ b_len, b_src, b_ty }, | 23131 | .{ b_len, b_src, b_ty }, |
| 23020 | }; | 23132 | }; |
| 23021 | | 23133 | |
| 23022 | for (0..@as(usize, @intCast(mask_len))) |i| { | 23134 | for (0..@intCast(mask_len)) |i| { |
| 23023 | const elem = try mask.elemValue(sema.mod, i); | 23135 | const elem = try mask.elemValue(sema.mod, i); |
| 23024 | if (elem.isUndef(mod)) continue; | 23136 | if (elem.isUndef(mod)) continue; |
| 23025 | const int = elem.toSignedInt(mod); | 23137 | const int = elem.toSignedInt(mod); |
| 23026 | var unsigned: u32 = undefined; | 23138 | var unsigned: u32 = undefined; |
| 23027 | var chosen: u32 = undefined; | 23139 | var chosen: u32 = undefined; |
| 23028 | if (int >= 0) { | 23140 | if (int >= 0) { |
| 23029 | unsigned = @as(u32, @intCast(int)); | 23141 | unsigned = @intCast(int); |
| 23030 | chosen = 0; | 23142 | chosen = 0; |
| 23031 | } else { | 23143 | } else { |
| 23032 | unsigned = @as(u32, @intCast(~int)); | 23144 | unsigned = @intCast(~int); |
| 23033 | chosen = 1; | 23145 | chosen = 1; |
| 23034 | } | 23146 | } |
| 23035 | if (unsigned >= operand_info[chosen][0]) { | 23147 | if (unsigned >= operand_info[chosen][0]) { |
| ... | @@ -23048,7 +23160,7 @@ fn analyzeShuffle( | ... | @@ -23048,7 +23160,7 @@ fn analyzeShuffle( |
| 23048 | | 23160 | |
| 23049 | break :msg msg; | 23161 | break :msg msg; |
| 23050 | }; | 23162 | }; |
| 23051 | return sema.failWithOwnedErrorMsg(msg); | 23163 | return sema.failWithOwnedErrorMsg(block, msg); |
| 23052 | } | 23164 | } |
| 23053 | } | 23165 | } |
| 23054 | | 23166 | |
| ... | @@ -23062,7 +23174,7 @@ fn analyzeShuffle( | ... | @@ -23062,7 +23174,7 @@ fn analyzeShuffle( |
| 23062 | continue; | 23174 | continue; |
| 23063 | } | 23175 | } |
| 23064 | const int = mask_elem_val.toSignedInt(mod); | 23176 | const int = mask_elem_val.toSignedInt(mod); |
| 23065 | const unsigned = if (int >= 0) @as(u32, @intCast(int)) else @as(u32, @intCast(~int)); | 23177 | const unsigned: u32 = @intCast(if (int >= 0) int else ~int); |
| 23066 | values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod); | 23178 | values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod); |
| 23067 | } | 23179 | } |
| 23068 | return Air.internedToRef((try mod.intern(.{ .aggregate = .{ | 23180 | return Air.internedToRef((try mod.intern(.{ .aggregate = .{ |
| ... | @@ -23083,23 +23195,23 @@ fn analyzeShuffle( | ... | @@ -23083,23 +23195,23 @@ fn analyzeShuffle( |
| 23083 | const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len)); | 23195 | const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len)); |
| 23084 | | 23196 | |
| 23085 | const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len); | 23197 | const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len); |
| 23086 | for (@as(usize, @intCast(0))..@as(usize, @intCast(min_len))) |i| { | 23198 | for (@intCast(0)..@intCast(min_len)) |i| { |
| 23087 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern(); | 23199 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern(); |
| 23088 | } | 23200 | } |
| 23089 | for (@as(usize, @intCast(min_len))..@as(usize, @intCast(max_len))) |i| { | 23201 | for (@intCast(min_len)..@intCast(max_len)) |i| { |
| 23090 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern(); | 23202 | expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern(); |
| 23091 | } | 23203 | } |
| 23092 | const expand_mask = try mod.intern(.{ .aggregate = .{ | 23204 | const expand_mask = try mod.intern(.{ .aggregate = .{ |
| 23093 | .ty = (try mod.vectorType(.{ .len = @as(u32, @intCast(max_len)), .child = .comptime_int_type })).toIntern(), | 23205 | .ty = (try mod.vectorType(.{ .len = @intCast(max_len), .child = .comptime_int_type })).toIntern(), |
| 23094 | .storage = .{ .elems = expand_mask_values }, | 23206 | .storage = .{ .elems = expand_mask_values }, |
| 23095 | } }); | 23207 | } }); |
| 23096 | | 23208 | |
| 23097 | if (a_len < b_len) { | 23209 | if (a_len < b_len) { |
| 23098 | const undef = try mod.undefRef(a_ty); | 23210 | const undef = try mod.undefRef(a_ty); |
| 23099 | a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @as(u32, @intCast(max_len))); | 23211 | a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(max_len)); |
| 23100 | } else { | 23212 | } else { |
| 23101 | const undef = try mod.undefRef(b_ty); | 23213 | const undef = try mod.undefRef(b_ty); |
| 23102 | b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @as(u32, @intCast(max_len))); | 23214 | b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(max_len)); |
| 23103 | } | 23215 | } |
| 23104 | } | 23216 | } |
| 23105 | | 23217 | |
| ... | @@ -23136,7 +23248,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -23136,7 +23248,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 23136 | .Vector, .Array => pred_ty.arrayLen(mod), | 23248 | .Vector, .Array => pred_ty.arrayLen(mod), |
| 23137 | else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}), | 23249 | else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}), |
| 23138 | }; | 23250 | }; |
| 23139 | const vec_len = @as(u32, @intCast(try sema.usizeCast(block, pred_src, vec_len_u64))); | 23251 | const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64)); |
| 23140 | | 23252 | |
| 23141 | const bool_vec_ty = try mod.vectorType(.{ | 23253 | const bool_vec_ty = try mod.vectorType(.{ |
| 23142 | .len = vec_len, | 23254 | .len = vec_len, |
| ... | @@ -23218,7 +23330,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -23218,7 +23330,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23218 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 23330 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 23219 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 23331 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23220 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); | 23332 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); |
| 23221 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicLoad must be comptime-known"); | 23333 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23334 | .needed_comptime_reason = "atomic order of @atomicLoad must be comptime-known", |
| | 23335 | }); |
| 23222 | | 23336 | |
| 23223 | switch (order) { | 23337 | switch (order) { |
| 23224 | .Release, .AcqRel => { | 23338 | .Release, .AcqRel => { |
| ... | @@ -23283,7 +23397,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -23283,7 +23397,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23283 | }, | 23397 | }, |
| 23284 | else => {}, | 23398 | else => {}, |
| 23285 | } | 23399 | } |
| 23286 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicRmW must be comptime-known"); | 23400 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23401 | .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known", |
| | 23402 | }); |
| 23287 | | 23403 | |
| 23288 | if (order == .Unordered) { | 23404 | if (order == .Unordered) { |
| 23289 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); | 23405 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| ... | @@ -23350,7 +23466,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23350,7 +23466,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23350 | const elem_ty = sema.typeOf(operand); | 23466 | const elem_ty = sema.typeOf(operand); |
| 23351 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 23467 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23352 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 23468 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 23353 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicStore must be comptime-known"); | 23469 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ |
| | 23470 | .needed_comptime_reason = "atomic order of @atomicStore must be comptime-known", |
| | 23471 | }); |
| 23354 | | 23472 | |
| 23355 | const air_tag: Air.Inst.Tag = switch (order) { | 23473 | const air_tag: Air.Inst.Tag = switch (order) { |
| 23356 | .Acquire, .AcqRel => { | 23474 | .Acquire, .AcqRel => { |
| ... | @@ -23451,7 +23569,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23451,7 +23569,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23451 | const modifier_ty = try sema.getBuiltinType("CallModifier"); | 23569 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 23452 | const air_ref = try sema.resolveInst(extra.modifier); | 23570 | const air_ref = try sema.resolveInst(extra.modifier); |
| 23453 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); | 23571 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 23454 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known"); | 23572 | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{ |
| | 23573 | .needed_comptime_reason = "call modifier must be comptime-known", |
| | 23574 | }); |
| 23455 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); | 23575 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); |
| 23456 | switch (modifier) { | 23576 | switch (modifier) { |
| 23457 | // These can be upgraded to comptime or nosuspend calls. | 23577 | // These can be upgraded to comptime or nosuspend calls. |
| ... | @@ -23504,7 +23624,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -23504,7 +23624,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23504 | | 23624 | |
| 23505 | var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); | 23625 | var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod)); |
| 23506 | for (resolved_args, 0..) |*resolved, i| { | 23626 | for (resolved_args, 0..) |*resolved, i| { |
| 23507 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @as(u32, @intCast(i)), args_ty); | 23627 | resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty); |
| 23508 | } | 23628 | } |
| 23509 | | 23629 | |
| 23510 | const callee_ty = sema.typeOf(func); | 23630 | const callee_ty = sema.typeOf(func); |
| ... | @@ -23536,7 +23656,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -23536,7 +23656,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 23536 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 23656 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 23537 | | 23657 | |
| 23538 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); | 23658 | const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type); |
| 23539 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, "field name must be comptime-known"); | 23659 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, .{ |
| | 23660 | .needed_comptime_reason = "field name must be comptime-known", |
| | 23661 | }); |
| 23540 | const field_ptr = try sema.resolveInst(extra.field_ptr); | 23662 | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 23541 | const field_ptr_ty = sema.typeOf(field_ptr); | 23663 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 23542 | const mod = sema.mod; | 23664 | const mod = sema.mod; |
| ... | @@ -23623,7 +23745,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -23623,7 +23745,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 23623 | try sema.addDeclaredHereNote(msg, parent_ty); | 23745 | try sema.addDeclaredHereNote(msg, parent_ty); |
| 23624 | break :msg msg; | 23746 | break :msg msg; |
| 23625 | }; | 23747 | }; |
| 23626 | return sema.failWithOwnedErrorMsg(msg); | 23748 | return sema.failWithOwnedErrorMsg(block, msg); |
| 23627 | } | 23749 | } |
| 23628 | return Air.internedToRef(field.base); | 23750 | return Air.internedToRef(field.base); |
| 23629 | } | 23751 | } |
| ... | @@ -23636,7 +23758,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -23636,7 +23758,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 23636 | .ty = Air.internedToRef(result_ptr.toIntern()), | 23758 | .ty = Air.internedToRef(result_ptr.toIntern()), |
| 23637 | .payload = try block.sema.addExtra(Air.FieldParentPtr{ | 23759 | .payload = try block.sema.addExtra(Air.FieldParentPtr{ |
| 23638 | .field_ptr = casted_field_ptr, | 23760 | .field_ptr = casted_field_ptr, |
| 23639 | .field_index = @as(u32, @intCast(field_index)), | 23761 | .field_index = @intCast(field_index), |
| 23640 | }), | 23762 | }), |
| 23641 | } }, | 23763 | } }, |
| 23642 | }); | 23764 | }); |
| ... | @@ -23977,7 +24099,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -23977,7 +24099,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 23977 | }); | 24099 | }); |
| 23978 | break :msg msg; | 24100 | break :msg msg; |
| 23979 | }; | 24101 | }; |
| 23980 | return sema.failWithOwnedErrorMsg(msg); | 24102 | return sema.failWithOwnedErrorMsg(block, msg); |
| 23981 | } | 24103 | } |
| 23982 | | 24104 | |
| 23983 | var len_val: ?Value = null; | 24105 | var len_val: ?Value = null; |
| ... | @@ -23999,7 +24121,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -23999,7 +24121,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 23999 | }); | 24121 | }); |
| 24000 | break :msg msg; | 24122 | break :msg msg; |
| 24001 | }; | 24123 | }; |
| 24002 | return sema.failWithOwnedErrorMsg(msg); | 24124 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24003 | } | 24125 | } |
| 24004 | break :check; | 24126 | break :check; |
| 24005 | } | 24127 | } |
| ... | @@ -24192,7 +24314,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -24192,7 +24314,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 24192 | }, | 24314 | }, |
| 24193 | .Many, .C => {}, | 24315 | .Many, .C => {}, |
| 24194 | } | 24316 | } |
| 24195 | return sema.failWithOwnedErrorMsg(msg: { | 24317 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 24196 | const msg = try sema.errMsg(block, src, "unknown @memset length", .{}); | 24318 | const msg = try sema.errMsg(block, src, "unknown @memset length", .{}); |
| 24197 | errdefer msg.destroy(sema.gpa); | 24319 | errdefer msg.destroy(sema.gpa); |
| 24198 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ | 24320 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ |
| ... | @@ -24295,7 +24417,7 @@ fn zirVarExtended( | ... | @@ -24295,7 +24417,7 @@ fn zirVarExtended( |
| 24295 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); | 24417 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 24296 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; | 24418 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; |
| 24297 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; | 24419 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; |
| 24298 | const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small)); | 24420 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); |
| 24299 | | 24421 | |
| 24300 | var extra_index: usize = extra.end; | 24422 | var extra_index: usize = extra.end; |
| 24301 | | 24423 | |
| ... | @@ -24310,7 +24432,7 @@ fn zirVarExtended( | ... | @@ -24310,7 +24432,7 @@ fn zirVarExtended( |
| 24310 | assert(!small.has_align); | 24432 | assert(!small.has_align); |
| 24311 | | 24433 | |
| 24312 | const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: { | 24434 | const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: { |
| 24313 | const init_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24435 | const init_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24314 | extra_index += 1; | 24436 | extra_index += 1; |
| 24315 | break :blk try sema.resolveInst(init_ref); | 24437 | break :blk try sema.resolveInst(init_ref); |
| 24316 | } else .none; | 24438 | } else .none; |
| ... | @@ -24327,8 +24449,11 @@ fn zirVarExtended( | ... | @@ -24327,8 +24449,11 @@ fn zirVarExtended( |
| 24327 | else | 24449 | else |
| 24328 | uncasted_init; | 24450 | uncasted_init; |
| 24329 | | 24451 | |
| 24330 | break :blk ((try sema.resolveMaybeUndefVal(init)) orelse | 24452 | break :blk ((try sema.resolveMaybeUndefVal(init)) orelse { |
| 24331 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known")).toIntern(); | 24453 | return sema.failWithNeededComptime(block, init_src, .{ |
| | 24454 | .needed_comptime_reason = "container level variable initializers must be comptime-known", |
| | 24455 | }); |
| | 24456 | }).toIntern(); |
| 24332 | } else .none; | 24457 | } else .none; |
| 24333 | | 24458 | |
| 24334 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); | 24459 | try sema.validateVarType(block, ty_src, var_ty, small.is_extern); |
| ... | @@ -24383,11 +24508,13 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24383,11 +24508,13 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24383 | const body = sema.code.extra[extra_index..][0..body_len]; | 24508 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 24384 | extra_index += body.len; | 24509 | extra_index += body.len; |
| 24385 | | 24510 | |
| 24386 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, "alignment must be comptime-known"); | 24511 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{ |
| | 24512 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 24513 | }); |
| 24387 | if (val.isGenericPoison()) { | 24514 | if (val.isGenericPoison()) { |
| 24388 | break :blk null; | 24515 | break :blk null; |
| 24389 | } | 24516 | } |
| 24390 | const alignment = @as(u32, @intCast(val.toUnsignedInt(mod))); | 24517 | const alignment: u32 = @intCast(val.toUnsignedInt(mod)); |
| 24391 | try sema.validateAlign(block, align_src, alignment); | 24518 | try sema.validateAlign(block, align_src, alignment); |
| 24392 | if (alignment == target_util.defaultFunctionAlignment(target)) { | 24519 | if (alignment == target_util.defaultFunctionAlignment(target)) { |
| 24393 | break :blk .none; | 24520 | break :blk .none; |
| ... | @@ -24395,15 +24522,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24395,15 +24522,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24395 | break :blk Alignment.fromNonzeroByteUnits(alignment); | 24522 | break :blk Alignment.fromNonzeroByteUnits(alignment); |
| 24396 | } | 24523 | } |
| 24397 | } else if (extra.data.bits.has_align_ref) blk: { | 24524 | } else if (extra.data.bits.has_align_ref) blk: { |
| 24398 | const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24525 | const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24399 | extra_index += 1; | 24526 | extra_index += 1; |
| 24400 | const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) { | 24527 | const align_tv = sema.resolveInstConst(block, align_src, align_ref, .{ |
| | 24528 | .needed_comptime_reason = "alignment must be comptime-known", |
| | 24529 | }) catch |err| switch (err) { |
| 24401 | error.GenericPoison => { | 24530 | error.GenericPoison => { |
| 24402 | break :blk null; | 24531 | break :blk null; |
| 24403 | }, | 24532 | }, |
| 24404 | else => |e| return e, | 24533 | else => |e| return e, |
| 24405 | }; | 24534 | }; |
| 24406 | const alignment = @as(u32, @intCast(align_tv.val.toUnsignedInt(mod))); | 24535 | const alignment: u32 = @intCast(align_tv.val.toUnsignedInt(mod)); |
| 24407 | try sema.validateAlign(block, align_src, alignment); | 24536 | try sema.validateAlign(block, align_src, alignment); |
| 24408 | if (alignment == target_util.defaultFunctionAlignment(target)) { | 24537 | if (alignment == target_util.defaultFunctionAlignment(target)) { |
| 24409 | break :blk .none; | 24538 | break :blk .none; |
| ... | @@ -24419,15 +24548,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24419,15 +24548,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24419 | extra_index += body.len; | 24548 | extra_index += body.len; |
| 24420 | | 24549 | |
| 24421 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); | 24550 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 24422 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known"); | 24551 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{ |
| | 24552 | .needed_comptime_reason = "addrspace must be comptime-known", |
| | 24553 | }); |
| 24423 | if (val.isGenericPoison()) { | 24554 | if (val.isGenericPoison()) { |
| 24424 | break :blk null; | 24555 | break :blk null; |
| 24425 | } | 24556 | } |
| 24426 | break :blk mod.toEnum(std.builtin.AddressSpace, val); | 24557 | break :blk mod.toEnum(std.builtin.AddressSpace, val); |
| 24427 | } else if (extra.data.bits.has_addrspace_ref) blk: { | 24558 | } else if (extra.data.bits.has_addrspace_ref) blk: { |
| 24428 | const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24559 | const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24429 | extra_index += 1; | 24560 | extra_index += 1; |
| 24430 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) { | 24561 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, .{ |
| | 24562 | .needed_comptime_reason = "addrspace must be comptime-known", |
| | 24563 | }) catch |err| switch (err) { |
| 24431 | error.GenericPoison => { | 24564 | error.GenericPoison => { |
| 24432 | break :blk null; | 24565 | break :blk null; |
| 24433 | }, | 24566 | }, |
| ... | @@ -24443,15 +24576,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24443,15 +24576,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24443 | extra_index += body.len; | 24576 | extra_index += body.len; |
| 24444 | | 24577 | |
| 24445 | const ty = Type.slice_const_u8; | 24578 | const ty = Type.slice_const_u8; |
| 24446 | const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, "linksection must be comptime-known"); | 24579 | const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, .{ |
| | 24580 | .needed_comptime_reason = "linksection must be comptime-known", |
| | 24581 | }); |
| 24447 | if (val.isGenericPoison()) { | 24582 | if (val.isGenericPoison()) { |
| 24448 | break :blk .generic; | 24583 | break :blk .generic; |
| 24449 | } | 24584 | } |
| 24450 | break :blk .{ .explicit = try val.toIpString(ty, mod) }; | 24585 | break :blk .{ .explicit = try val.toIpString(ty, mod) }; |
| 24451 | } else if (extra.data.bits.has_section_ref) blk: { | 24586 | } else if (extra.data.bits.has_section_ref) blk: { |
| 24452 | const section_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24587 | const section_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24453 | extra_index += 1; | 24588 | extra_index += 1; |
| 24454 | const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) { | 24589 | const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, .{ |
| | 24590 | .needed_comptime_reason = "linksection must be comptime-known", |
| | 24591 | }) catch |err| switch (err) { |
| 24455 | error.GenericPoison => { | 24592 | error.GenericPoison => { |
| 24456 | break :blk .generic; | 24593 | break :blk .generic; |
| 24457 | }, | 24594 | }, |
| ... | @@ -24467,15 +24604,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24467,15 +24604,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24467 | extra_index += body.len; | 24604 | extra_index += body.len; |
| 24468 | | 24605 | |
| 24469 | const cc_ty = try sema.getBuiltinType("CallingConvention"); | 24606 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 24470 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known"); | 24607 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ |
| | 24608 | .needed_comptime_reason = "calling convention must be comptime-known", |
| | 24609 | }); |
| 24471 | if (val.isGenericPoison()) { | 24610 | if (val.isGenericPoison()) { |
| 24472 | break :blk null; | 24611 | break :blk null; |
| 24473 | } | 24612 | } |
| 24474 | break :blk mod.toEnum(std.builtin.CallingConvention, val); | 24613 | break :blk mod.toEnum(std.builtin.CallingConvention, val); |
| 24475 | } else if (extra.data.bits.has_cc_ref) blk: { | 24614 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 24476 | const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24615 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24477 | extra_index += 1; | 24616 | extra_index += 1; |
| 24478 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) { | 24617 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, .{ |
| | 24618 | .needed_comptime_reason = "calling convention must be comptime-known", |
| | 24619 | }) catch |err| switch (err) { |
| 24479 | error.GenericPoison => { | 24620 | error.GenericPoison => { |
| 24480 | break :blk null; | 24621 | break :blk null; |
| 24481 | }, | 24622 | }, |
| ... | @@ -24493,13 +24634,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24493,13 +24634,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24493 | const body = sema.code.extra[extra_index..][0..body_len]; | 24634 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 24494 | extra_index += body.len; | 24635 | extra_index += body.len; |
| 24495 | | 24636 | |
| 24496 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, "return type must be comptime-known"); | 24637 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ |
| | 24638 | .needed_comptime_reason = "return type must be comptime-known", |
| | 24639 | }); |
| 24497 | const ty = val.toType(); | 24640 | const ty = val.toType(); |
| 24498 | break :blk ty; | 24641 | break :blk ty; |
| 24499 | } else if (extra.data.bits.has_ret_ty_ref) blk: { | 24642 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| 24500 | const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index])); | 24643 | const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24501 | extra_index += 1; | 24644 | extra_index += 1; |
| 24502 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) { | 24645 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{ |
| | 24646 | .needed_comptime_reason = "return type must be comptime-known", |
| | 24647 | }) catch |err| switch (err) { |
| 24503 | error.GenericPoison => { | 24648 | error.GenericPoison => { |
| 24504 | break :blk Type.generic_poison; | 24649 | break :blk Type.generic_poison; |
| 24505 | }, | 24650 | }, |
| ... | @@ -24554,9 +24699,11 @@ fn zirCUndef( | ... | @@ -24554,9 +24699,11 @@ fn zirCUndef( |
| 24554 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 24699 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 24555 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24700 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24556 | | 24701 | |
| 24557 | const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known"); | 24702 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| | 24703 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| | 24704 | }); |
| 24558 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); | 24705 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); |
| 24559 | return Air.Inst.Ref.void_value; | 24706 | return .void_value; |
| 24560 | } | 24707 | } |
| 24561 | | 24708 | |
| 24562 | fn zirCInclude( | 24709 | fn zirCInclude( |
| ... | @@ -24567,9 +24714,11 @@ fn zirCInclude( | ... | @@ -24567,9 +24714,11 @@ fn zirCInclude( |
| 24567 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 24714 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 24568 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24715 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24569 | | 24716 | |
| 24570 | const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime-known"); | 24717 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| | 24718 | .needed_comptime_reason = "path being included must be comptime-known", |
| | 24719 | }); |
| 24571 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); | 24720 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); |
| 24572 | return Air.Inst.Ref.void_value; | 24721 | return .void_value; |
| 24573 | } | 24722 | } |
| 24574 | | 24723 | |
| 24575 | fn zirCDefine( | 24724 | fn zirCDefine( |
| ... | @@ -24582,15 +24731,19 @@ fn zirCDefine( | ... | @@ -24582,15 +24731,19 @@ fn zirCDefine( |
| 24582 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24731 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24583 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24732 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 24584 | | 24733 | |
| 24585 | const name = try sema.resolveConstString(block, name_src, extra.lhs, "name of macro being undefined must be comptime-known"); | 24734 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ |
| | 24735 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| | 24736 | }); |
| 24586 | const rhs = try sema.resolveInst(extra.rhs); | 24737 | const rhs = try sema.resolveInst(extra.rhs); |
| 24587 | if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) { | 24738 | if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) { |
| 24588 | const value = try sema.resolveConstString(block, val_src, extra.rhs, "value of macro being undefined must be comptime-known"); | 24739 | const value = try sema.resolveConstString(block, val_src, extra.rhs, .{ |
| | 24740 | .needed_comptime_reason = "value of macro being undefined must be comptime-known", |
| | 24741 | }); |
| 24589 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); | 24742 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); |
| 24590 | } else { | 24743 | } else { |
| 24591 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); | 24744 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); |
| 24592 | } | 24745 | } |
| 24593 | return Air.Inst.Ref.void_value; | 24746 | return .void_value; |
| 24594 | } | 24747 | } |
| 24595 | | 24748 | |
| 24596 | fn zirWasmMemorySize( | 24749 | fn zirWasmMemorySize( |
| ... | @@ -24606,7 +24759,9 @@ fn zirWasmMemorySize( | ... | @@ -24606,7 +24759,9 @@ fn zirWasmMemorySize( |
| 24606 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 24759 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 24607 | } | 24760 | } |
| 24608 | | 24761 | |
| 24609 | const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known"))); | 24762 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{ |
| | 24763 | .needed_comptime_reason = "wasm memory size index must be comptime-known", |
| | 24764 | })); |
| 24610 | try sema.requireRuntimeBlock(block, builtin_src, null); | 24765 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 24611 | return block.addInst(.{ | 24766 | return block.addInst(.{ |
| 24612 | .tag = .wasm_memory_size, | 24767 | .tag = .wasm_memory_size, |
| ... | @@ -24631,7 +24786,9 @@ fn zirWasmMemoryGrow( | ... | @@ -24631,7 +24786,9 @@ fn zirWasmMemoryGrow( |
| 24631 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 24786 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 24632 | } | 24787 | } |
| 24633 | | 24788 | |
| 24634 | const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known"))); | 24789 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ |
| | 24790 | .needed_comptime_reason = "wasm memory size index must be comptime-known", |
| | 24791 | })); |
| 24635 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); | 24792 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); |
| 24636 | | 24793 | |
| 24637 | try sema.requireRuntimeBlock(block, builtin_src, null); | 24794 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| ... | @@ -24661,17 +24818,23 @@ fn resolvePrefetchOptions( | ... | @@ -24661,17 +24818,23 @@ fn resolvePrefetchOptions( |
| 24661 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); | 24818 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 24662 | | 24819 | |
| 24663 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); | 24820 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); |
| 24664 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known"); | 24821 | const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{ |
| | 24822 | .needed_comptime_reason = "prefetch read/write must be comptime-known", |
| | 24823 | }); |
| 24665 | | 24824 | |
| 24666 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); | 24825 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); |
| 24667 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known"); | 24826 | const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{ |
| | 24827 | .needed_comptime_reason = "prefetch locality must be comptime-known", |
| | 24828 | }); |
| 24668 | | 24829 | |
| 24669 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); | 24830 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); |
| 24670 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known"); | 24831 | const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{ |
| | 24832 | .needed_comptime_reason = "prefetch cache must be comptime-known", |
| | 24833 | }); |
| 24671 | | 24834 | |
| 24672 | return std.builtin.PrefetchOptions{ | 24835 | return std.builtin.PrefetchOptions{ |
| 24673 | .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), | 24836 | .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), |
| 24674 | .locality = @as(u2, @intCast(locality_val.toUnsignedInt(mod))), | 24837 | .locality = @intCast(locality_val.toUnsignedInt(mod)), |
| 24675 | .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val), | 24838 | .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val), |
| 24676 | }; | 24839 | }; |
| 24677 | } | 24840 | } |
| ... | @@ -24707,7 +24870,7 @@ fn zirPrefetch( | ... | @@ -24707,7 +24870,7 @@ fn zirPrefetch( |
| 24707 | }); | 24870 | }); |
| 24708 | } | 24871 | } |
| 24709 | | 24872 | |
| 24710 | return Air.Inst.Ref.void_value; | 24873 | return .void_value; |
| 24711 | } | 24874 | } |
| 24712 | | 24875 | |
| 24713 | fn resolveExternOptions( | 24876 | fn resolveExternOptions( |
| ... | @@ -24734,18 +24897,26 @@ fn resolveExternOptions( | ... | @@ -24734,18 +24897,26 @@ fn resolveExternOptions( |
| 24734 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); | 24897 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 24735 | | 24898 | |
| 24736 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); | 24899 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 24737 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known"); | 24900 | const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{ |
| | 24901 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", |
| | 24902 | }); |
| 24738 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); | 24903 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| 24739 | | 24904 | |
| 24740 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); | 24905 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); |
| 24741 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known"); | 24906 | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{ |
| | 24907 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", |
| | 24908 | }); |
| 24742 | | 24909 | |
| 24743 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); | 24910 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 24744 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known"); | 24911 | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{ |
| | 24912 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", |
| | 24913 | }); |
| 24745 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); | 24914 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 24746 | | 24915 | |
| 24747 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); | 24916 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); |
| 24748 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known"); | 24917 | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{ |
| | 24918 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", |
| | 24919 | }); |
| 24749 | | 24920 | |
| 24750 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { | 24921 | const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: { |
| 24751 | const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); | 24922 | const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| ... | @@ -24793,7 +24964,7 @@ fn zirBuiltinExtern( | ... | @@ -24793,7 +24964,7 @@ fn zirBuiltinExtern( |
| 24793 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other); | 24964 | try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other); |
| 24794 | break :msg msg; | 24965 | break :msg msg; |
| 24795 | }; | 24966 | }; |
| 24796 | return sema.failWithOwnedErrorMsg(msg); | 24967 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24797 | } | 24968 | } |
| 24798 | | 24969 | |
| 24799 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { | 24970 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| ... | @@ -24870,7 +25041,9 @@ fn zirWorkItem( | ... | @@ -24870,7 +25041,9 @@ fn zirWorkItem( |
| 24870 | }, | 25041 | }, |
| 24871 | } | 25042 | } |
| 24872 | | 25043 | |
| 24873 | const dimension = @as(u32, @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known"))); | 25044 | const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{ |
| | 25045 | .needed_comptime_reason = "dimension must be comptime-known", |
| | 25046 | })); |
| 24874 | try sema.requireRuntimeBlock(block, builtin_src, null); | 25047 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 24875 | | 25048 | |
| 24876 | return block.addInst(.{ | 25049 | return block.addInst(.{ |
| ... | @@ -24892,11 +25065,7 @@ fn zirInComptime( | ... | @@ -24892,11 +25065,7 @@ fn zirInComptime( |
| 24892 | block: *Block, | 25065 | block: *Block, |
| 24893 | ) CompileError!Air.Inst.Ref { | 25066 | ) CompileError!Air.Inst.Ref { |
| 24894 | _ = sema; | 25067 | _ = sema; |
| 24895 | if (block.is_comptime) { | 25068 | return if (block.is_comptime) .bool_true else .bool_false; |
| 24896 | return Air.Inst.Ref.bool_true; | | |
| 24897 | } else { | | |
| 24898 | return Air.Inst.Ref.bool_false; | | |
| 24899 | } | | |
| 24900 | } | 25069 | } |
| 24901 | | 25070 | |
| 24902 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { | 25071 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| ... | @@ -24913,7 +25082,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: | ... | @@ -24913,7 +25082,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: |
| 24913 | } | 25082 | } |
| 24914 | break :msg msg; | 25083 | break :msg msg; |
| 24915 | }; | 25084 | }; |
| 24916 | return sema.failWithOwnedErrorMsg(msg); | 25085 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24917 | } | 25086 | } |
| 24918 | } | 25087 | } |
| 24919 | | 25088 | |
| ... | @@ -24935,7 +25104,7 @@ fn validateVarType( | ... | @@ -24935,7 +25104,7 @@ fn validateVarType( |
| 24935 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other); | 25104 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other); |
| 24936 | break :msg msg; | 25105 | break :msg msg; |
| 24937 | }; | 25106 | }; |
| 24938 | return sema.failWithOwnedErrorMsg(msg); | 25107 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24939 | } | 25108 | } |
| 24940 | } else { | 25109 | } else { |
| 24941 | if (var_ty.zigTypeTag(mod) == .Opaque) { | 25110 | if (var_ty.zigTypeTag(mod) == .Opaque) { |
| ... | @@ -24962,7 +25131,7 @@ fn validateVarType( | ... | @@ -24962,7 +25131,7 @@ fn validateVarType( |
| 24962 | | 25131 | |
| 24963 | break :msg msg; | 25132 | break :msg msg; |
| 24964 | }; | 25133 | }; |
| 24965 | return sema.failWithOwnedErrorMsg(msg); | 25134 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24966 | } | 25135 | } |
| 24967 | | 25136 | |
| 24968 | const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); | 25137 | const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); |
| ... | @@ -25412,7 +25581,7 @@ fn addSafetyCheckExtra( | ... | @@ -25412,7 +25581,7 @@ fn addSafetyCheckExtra( |
| 25412 | fail_block.instructions.items.len); | 25581 | fail_block.instructions.items.len); |
| 25413 | | 25582 | |
| 25414 | try sema.air_instructions.ensureUnusedCapacity(gpa, 3); | 25583 | try sema.air_instructions.ensureUnusedCapacity(gpa, 3); |
| 25415 | const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len)); | 25584 | const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len); |
| 25416 | const cond_br_inst = block_inst + 1; | 25585 | const cond_br_inst = block_inst + 1; |
| 25417 | const br_inst = cond_br_inst + 1; | 25586 | const br_inst = cond_br_inst + 1; |
| 25418 | sema.air_instructions.appendAssumeCapacity(.{ | 25587 | sema.air_instructions.appendAssumeCapacity(.{ |
| ... | @@ -25432,7 +25601,7 @@ fn addSafetyCheckExtra( | ... | @@ -25432,7 +25601,7 @@ fn addSafetyCheckExtra( |
| 25432 | .operand = ok, | 25601 | .operand = ok, |
| 25433 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ | 25602 | .payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 25434 | .then_body_len = 1, | 25603 | .then_body_len = 1, |
| 25435 | .else_body_len = @as(u32, @intCast(fail_block.instructions.items.len)), | 25604 | .else_body_len = @intCast(fail_block.instructions.items.len), |
| 25436 | }), | 25605 | }), |
| 25437 | } }, | 25606 | } }, |
| 25438 | }); | 25607 | }); |
| ... | @@ -25648,7 +25817,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | ... | @@ -25648,7 +25817,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 25648 | "use @setEvalBranchQuota() to raise the branch limit from {d}", | 25817 | "use @setEvalBranchQuota() to raise the branch limit from {d}", |
| 25649 | .{sema.branch_quota}, | 25818 | .{sema.branch_quota}, |
| 25650 | ); | 25819 | ); |
| 25651 | return sema.failWithOwnedErrorMsg(msg); | 25820 | return sema.failWithOwnedErrorMsg(block, msg); |
| 25652 | } | 25821 | } |
| 25653 | } | 25822 | } |
| 25654 | | 25823 | |
| ... | @@ -25755,7 +25924,7 @@ fn fieldVal( | ... | @@ -25755,7 +25924,7 @@ fn fieldVal( |
| 25755 | try sema.addDeclaredHereNote(msg, child_type); | 25924 | try sema.addDeclaredHereNote(msg, child_type); |
| 25756 | break :msg msg; | 25925 | break :msg msg; |
| 25757 | }; | 25926 | }; |
| 25758 | return sema.failWithOwnedErrorMsg(msg); | 25927 | return sema.failWithOwnedErrorMsg(block, msg); |
| 25759 | }, | 25928 | }, |
| 25760 | .inferred_error_set_type => { | 25929 | .inferred_error_set_type => { |
| 25761 | return sema.fail(block, src, "TODO handle inferred error sets here", .{}); | 25930 | return sema.fail(block, src, "TODO handle inferred error sets here", .{}); |
| ... | @@ -25785,7 +25954,7 @@ fn fieldVal( | ... | @@ -25785,7 +25954,7 @@ fn fieldVal( |
| 25785 | try sema.resolveTypeFields(child_type); | 25954 | try sema.resolveTypeFields(child_type); |
| 25786 | if (child_type.unionTagType(mod)) |enum_ty| { | 25955 | if (child_type.unionTagType(mod)) |enum_ty| { |
| 25787 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| { | 25956 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| { |
| 25788 | const field_index = @as(u32, @intCast(field_index_usize)); | 25957 | const field_index: u32 = @intCast(field_index_usize); |
| 25789 | return Air.internedToRef((try mod.enumValueFieldIndex(enum_ty, field_index)).toIntern()); | 25958 | return Air.internedToRef((try mod.enumValueFieldIndex(enum_ty, field_index)).toIntern()); |
| 25790 | } | 25959 | } |
| 25791 | } | 25960 | } |
| ... | @@ -25799,7 +25968,7 @@ fn fieldVal( | ... | @@ -25799,7 +25968,7 @@ fn fieldVal( |
| 25799 | } | 25968 | } |
| 25800 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse | 25969 | const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse |
| 25801 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 25970 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 25802 | const field_index = @as(u32, @intCast(field_index_usize)); | 25971 | const field_index: u32 = @intCast(field_index_usize); |
| 25803 | const enum_val = try mod.enumValueFieldIndex(child_type, field_index); | 25972 | const enum_val = try mod.enumValueFieldIndex(child_type, field_index); |
| 25804 | return Air.internedToRef(enum_val.toIntern()); | 25973 | return Air.internedToRef(enum_val.toIntern()); |
| 25805 | }, | 25974 | }, |
| ... | @@ -25819,7 +25988,7 @@ fn fieldVal( | ... | @@ -25819,7 +25988,7 @@ fn fieldVal( |
| 25819 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); | 25988 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); |
| 25820 | break :msg msg; | 25989 | break :msg msg; |
| 25821 | }; | 25990 | }; |
| 25822 | return sema.failWithOwnedErrorMsg(msg); | 25991 | return sema.failWithOwnedErrorMsg(block, msg); |
| 25823 | }, | 25992 | }, |
| 25824 | } | 25993 | } |
| 25825 | }, | 25994 | }, |
| ... | @@ -25956,7 +26125,7 @@ fn fieldPtr( | ... | @@ -25956,7 +26125,7 @@ fn fieldPtr( |
| 25956 | } | 26125 | } |
| 25957 | }, | 26126 | }, |
| 25958 | .Type => { | 26127 | .Type => { |
| 25959 | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, ""); | 26128 | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined); |
| 25960 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); | 26129 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 25961 | const inner = if (is_pointer_to) | 26130 | const inner = if (is_pointer_to) |
| 25962 | try sema.analyzeLoad(block, src, result, object_ptr_src) | 26131 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | @@ -26011,7 +26180,7 @@ fn fieldPtr( | ... | @@ -26011,7 +26180,7 @@ fn fieldPtr( |
| 26011 | try sema.resolveTypeFields(child_type); | 26180 | try sema.resolveTypeFields(child_type); |
| 26012 | if (child_type.unionTagType(mod)) |enum_ty| { | 26181 | if (child_type.unionTagType(mod)) |enum_ty| { |
| 26013 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| { | 26182 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| { |
| 26014 | const field_index_u32 = @as(u32, @intCast(field_index)); | 26183 | const field_index_u32: u32 = @intCast(field_index); |
| 26015 | var anon_decl = try block.startAnonDecl(); | 26184 | var anon_decl = try block.startAnonDecl(); |
| 26016 | defer anon_decl.deinit(); | 26185 | defer anon_decl.deinit(); |
| 26017 | return sema.analyzeDeclRef(try anon_decl.finish( | 26186 | return sema.analyzeDeclRef(try anon_decl.finish( |
| ... | @@ -26032,7 +26201,7 @@ fn fieldPtr( | ... | @@ -26032,7 +26201,7 @@ fn fieldPtr( |
| 26032 | const field_index = child_type.enumFieldIndex(field_name, mod) orelse { | 26201 | const field_index = child_type.enumFieldIndex(field_name, mod) orelse { |
| 26033 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); | 26202 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 26034 | }; | 26203 | }; |
| 26035 | const field_index_u32 = @as(u32, @intCast(field_index)); | 26204 | const field_index_u32: u32 = @intCast(field_index); |
| 26036 | var anon_decl = try block.startAnonDecl(); | 26205 | var anon_decl = try block.startAnonDecl(); |
| 26037 | defer anon_decl.deinit(); | 26206 | defer anon_decl.deinit(); |
| 26038 | return sema.analyzeDeclRef(try anon_decl.finish( | 26207 | return sema.analyzeDeclRef(try anon_decl.finish( |
| ... | @@ -26117,7 +26286,7 @@ fn fieldCallBind( | ... | @@ -26117,7 +26286,7 @@ fn fieldCallBind( |
| 26117 | if (mod.typeToStruct(concrete_ty)) |struct_obj| { | 26286 | if (mod.typeToStruct(concrete_ty)) |struct_obj| { |
| 26118 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse | 26287 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse |
| 26119 | break :find_field; | 26288 | break :find_field; |
| 26120 | const field_index = @as(u32, @intCast(field_index_usize)); | 26289 | const field_index: u32 = @intCast(field_index_usize); |
| 26121 | const field = struct_obj.fields.values()[field_index]; | 26290 | const field = struct_obj.fields.values()[field_index]; |
| 26122 | | 26291 | |
| 26123 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); | 26292 | return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr); |
| ... | @@ -26132,7 +26301,7 @@ fn fieldCallBind( | ... | @@ -26132,7 +26301,7 @@ fn fieldCallBind( |
| 26132 | } else { | 26301 | } else { |
| 26133 | const max = concrete_ty.structFieldCount(mod); | 26302 | const max = concrete_ty.structFieldCount(mod); |
| 26134 | for (0..max) |i_usize| { | 26303 | for (0..max) |i_usize| { |
| 26135 | const i = @as(u32, @intCast(i_usize)); | 26304 | const i: u32 = @intCast(i_usize); |
| 26136 | if (field_name == concrete_ty.structFieldName(i, mod)) { | 26305 | if (field_name == concrete_ty.structFieldName(i, mod)) { |
| 26137 | return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.structFieldType(i, mod), i, object_ptr); | 26306 | return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.structFieldType(i, mod), i, object_ptr); |
| 26138 | } | 26307 | } |
| ... | @@ -26238,7 +26407,7 @@ fn fieldCallBind( | ... | @@ -26238,7 +26407,7 @@ fn fieldCallBind( |
| 26238 | } | 26407 | } |
| 26239 | break :msg msg; | 26408 | break :msg msg; |
| 26240 | }; | 26409 | }; |
| 26241 | return sema.failWithOwnedErrorMsg(msg); | 26410 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26242 | } | 26411 | } |
| 26243 | | 26412 | |
| 26244 | fn finishFieldCallBind( | 26413 | fn finishFieldCallBind( |
| ... | @@ -26302,7 +26471,7 @@ fn namespaceLookup( | ... | @@ -26302,7 +26471,7 @@ fn namespaceLookup( |
| 26302 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); | 26471 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); |
| 26303 | break :msg msg; | 26472 | break :msg msg; |
| 26304 | }; | 26473 | }; |
| 26305 | return sema.failWithOwnedErrorMsg(msg); | 26474 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26306 | } | 26475 | } |
| 26307 | return decl_index; | 26476 | return decl_index; |
| 26308 | } | 26477 | } |
| ... | @@ -26364,7 +26533,7 @@ fn structFieldPtr( | ... | @@ -26364,7 +26533,7 @@ fn structFieldPtr( |
| 26364 | | 26533 | |
| 26365 | const field_index_big = struct_obj.fields.getIndex(field_name) orelse | 26534 | const field_index_big = struct_obj.fields.getIndex(field_name) orelse |
| 26366 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name); | 26535 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name); |
| 26367 | const field_index = @as(u32, @intCast(field_index_big)); | 26536 | const field_index: u32 = @intCast(field_index_big); |
| 26368 | | 26537 | |
| 26369 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); | 26538 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); |
| 26370 | } | 26539 | } |
| ... | @@ -26413,7 +26582,7 @@ fn structFieldPtrByIndex( | ... | @@ -26413,7 +26582,7 @@ fn structFieldPtrByIndex( |
| 26413 | if (i == field_index) { | 26582 | if (i == field_index) { |
| 26414 | ptr_ty_data.packed_offset.bit_offset = running_bits; | 26583 | ptr_ty_data.packed_offset.bit_offset = running_bits; |
| 26415 | } | 26584 | } |
| 26416 | running_bits += @as(u16, @intCast(f.ty.bitSize(mod))); | 26585 | running_bits += @intCast(f.ty.bitSize(mod)); |
| 26417 | } | 26586 | } |
| 26418 | ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8; | 26587 | ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8; |
| 26419 | | 26588 | |
| ... | @@ -26441,7 +26610,7 @@ fn structFieldPtrByIndex( | ... | @@ -26441,7 +26610,7 @@ fn structFieldPtrByIndex( |
| 26441 | const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod); | 26610 | const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod); |
| 26442 | if (elem_size_bytes * 8 == elem_size_bits) { | 26611 | if (elem_size_bytes * 8 == elem_size_bits) { |
| 26443 | const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8; | 26612 | const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8; |
| 26444 | const new_align = @as(Alignment, @enumFromInt(@ctz(byte_offset | parent_align))); | 26613 | const new_align: Alignment = @enumFromInt(@ctz(byte_offset | parent_align)); |
| 26445 | assert(new_align != .none); | 26614 | assert(new_align != .none); |
| 26446 | ptr_ty_data.flags.alignment = new_align; | 26615 | ptr_ty_data.flags.alignment = new_align; |
| 26447 | ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 }; | 26616 | ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 }; |
| ... | @@ -26505,7 +26674,7 @@ fn structFieldVal( | ... | @@ -26505,7 +26674,7 @@ fn structFieldVal( |
| 26505 | | 26674 | |
| 26506 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse | 26675 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse |
| 26507 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name); | 26676 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name); |
| 26508 | const field_index = @as(u32, @intCast(field_index_usize)); | 26677 | const field_index: u32 = @intCast(field_index_usize); |
| 26509 | const field = struct_obj.fields.values()[field_index]; | 26678 | const field = struct_obj.fields.values()[field_index]; |
| 26510 | | 26679 | |
| 26511 | if (field.is_comptime) { | 26680 | if (field.is_comptime) { |
| ... | @@ -26660,7 +26829,7 @@ fn unionFieldPtr( | ... | @@ -26660,7 +26829,7 @@ fn unionFieldPtr( |
| 26660 | try sema.addDeclaredHereNote(msg, union_ty); | 26829 | try sema.addDeclaredHereNote(msg, union_ty); |
| 26661 | break :msg msg; | 26830 | break :msg msg; |
| 26662 | }; | 26831 | }; |
| 26663 | return sema.failWithOwnedErrorMsg(msg); | 26832 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26664 | } | 26833 | } |
| 26665 | | 26834 | |
| 26666 | if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: { | 26835 | if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: { |
| ... | @@ -26686,7 +26855,7 @@ fn unionFieldPtr( | ... | @@ -26686,7 +26855,7 @@ fn unionFieldPtr( |
| 26686 | try sema.addDeclaredHereNote(msg, union_ty); | 26855 | try sema.addDeclaredHereNote(msg, union_ty); |
| 26687 | break :msg msg; | 26856 | break :msg msg; |
| 26688 | }; | 26857 | }; |
| 26689 | return sema.failWithOwnedErrorMsg(msg); | 26858 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26690 | } | 26859 | } |
| 26691 | }, | 26860 | }, |
| 26692 | .Packed, .Extern => {}, | 26861 | .Packed, .Extern => {}, |
| ... | @@ -26713,7 +26882,7 @@ fn unionFieldPtr( | ... | @@ -26713,7 +26882,7 @@ fn unionFieldPtr( |
| 26713 | } | 26882 | } |
| 26714 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 26883 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 26715 | _ = try block.addNoOp(.unreach); | 26884 | _ = try block.addNoOp(.unreach); |
| 26716 | return Air.Inst.Ref.unreachable_value; | 26885 | return .unreachable_value; |
| 26717 | } | 26886 | } |
| 26718 | return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty); | 26887 | return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty); |
| 26719 | } | 26888 | } |
| ... | @@ -26758,7 +26927,7 @@ fn unionFieldVal( | ... | @@ -26758,7 +26927,7 @@ fn unionFieldVal( |
| 26758 | try sema.addDeclaredHereNote(msg, union_ty); | 26927 | try sema.addDeclaredHereNote(msg, union_ty); |
| 26759 | break :msg msg; | 26928 | break :msg msg; |
| 26760 | }; | 26929 | }; |
| 26761 | return sema.failWithOwnedErrorMsg(msg); | 26930 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26762 | } | 26931 | } |
| 26763 | }, | 26932 | }, |
| 26764 | .Packed, .Extern => { | 26933 | .Packed, .Extern => { |
| ... | @@ -26785,7 +26954,7 @@ fn unionFieldVal( | ... | @@ -26785,7 +26954,7 @@ fn unionFieldVal( |
| 26785 | } | 26954 | } |
| 26786 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 26955 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 26787 | _ = try block.addNoOp(.unreach); | 26956 | _ = try block.addNoOp(.unreach); |
| 26788 | return Air.Inst.Ref.unreachable_value; | 26957 | return .unreachable_value; |
| 26789 | } | 26958 | } |
| 26790 | return block.addStructFieldVal(union_byval, field_index, field_ty); | 26959 | return block.addStructFieldVal(union_byval, field_index, field_ty); |
| 26791 | } | 26960 | } |
| ... | @@ -26814,8 +26983,10 @@ fn elemPtr( | ... | @@ -26814,8 +26983,10 @@ fn elemPtr( |
| 26814 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), | 26983 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), |
| 26815 | .Struct => { | 26984 | .Struct => { |
| 26816 | // Tuple field access. | 26985 | // Tuple field access. |
| 26817 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 26986 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 26818 | const index = @as(u32, @intCast(index_val.toUnsignedInt(mod))); | 26987 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 26988 | }); |
| | 26989 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26819 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); | 26990 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); |
| 26820 | }, | 26991 | }, |
| 26821 | else => { | 26992 | else => { |
| ... | @@ -26850,7 +27021,7 @@ fn elemPtrOneLayerOnly( | ... | @@ -26850,7 +27021,7 @@ fn elemPtrOneLayerOnly( |
| 26850 | const runtime_src = rs: { | 27021 | const runtime_src = rs: { |
| 26851 | const ptr_val = maybe_ptr_val orelse break :rs indexable_src; | 27022 | const ptr_val = maybe_ptr_val orelse break :rs indexable_src; |
| 26852 | const index_val = maybe_index_val orelse break :rs elem_index_src; | 27023 | const index_val = maybe_index_val orelse break :rs elem_index_src; |
| 26853 | const index = @as(usize, @intCast(index_val.toUnsignedInt(mod))); | 27024 | const index: usize = @intCast(index_val.toUnsignedInt(mod)); |
| 26854 | const result_ty = try sema.elemPtrType(indexable_ty, index); | 27025 | const result_ty = try sema.elemPtrType(indexable_ty, index); |
| 26855 | const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod); | 27026 | const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod); |
| 26856 | return Air.internedToRef(elem_ptr.toIntern()); | 27027 | return Air.internedToRef(elem_ptr.toIntern()); |
| ... | @@ -26868,8 +27039,10 @@ fn elemPtrOneLayerOnly( | ... | @@ -26868,8 +27039,10 @@ fn elemPtrOneLayerOnly( |
| 26868 | }, | 27039 | }, |
| 26869 | .Struct => { | 27040 | .Struct => { |
| 26870 | assert(child_ty.isTuple(mod)); | 27041 | assert(child_ty.isTuple(mod)); |
| 26871 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 27042 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 26872 | const index = @as(u32, @intCast(index_val.toUnsignedInt(mod))); | 27043 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 27044 | }); |
| | 27045 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26873 | return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); | 27046 | return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); |
| 26874 | }, | 27047 | }, |
| 26875 | else => unreachable, // Guaranteed by checkIndexable | 27048 | else => unreachable, // Guaranteed by checkIndexable |
| ... | @@ -26907,7 +27080,7 @@ fn elemVal( | ... | @@ -26907,7 +27080,7 @@ fn elemVal( |
| 26907 | const runtime_src = rs: { | 27080 | const runtime_src = rs: { |
| 26908 | const indexable_val = maybe_indexable_val orelse break :rs indexable_src; | 27081 | const indexable_val = maybe_indexable_val orelse break :rs indexable_src; |
| 26909 | const index_val = maybe_index_val orelse break :rs elem_index_src; | 27082 | const index_val = maybe_index_val orelse break :rs elem_index_src; |
| 26910 | const index = @as(usize, @intCast(index_val.toUnsignedInt(mod))); | 27083 | const index: usize = @intCast(index_val.toUnsignedInt(mod)); |
| 26911 | const elem_ty = indexable_ty.elemType2(mod); | 27084 | const elem_ty = indexable_ty.elemType2(mod); |
| 26912 | const many_ptr_ty = try mod.manyConstPtrType(elem_ty); | 27085 | const many_ptr_ty = try mod.manyConstPtrType(elem_ty); |
| 26913 | const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty); | 27086 | const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty); |
| ... | @@ -26943,8 +27116,10 @@ fn elemVal( | ... | @@ -26943,8 +27116,10 @@ fn elemVal( |
| 26943 | }, | 27116 | }, |
| 26944 | .Struct => { | 27117 | .Struct => { |
| 26945 | // Tuple field access. | 27118 | // Tuple field access. |
| 26946 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known"); | 27119 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 26947 | const index = @as(u32, @intCast(index_val.toUnsignedInt(mod))); | 27120 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| | 27121 | }); |
| | 27122 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| 26948 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); | 27123 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); |
| 26949 | }, | 27124 | }, |
| 26950 | else => unreachable, | 27125 | else => unreachable, |
| ... | @@ -26975,7 +27150,7 @@ fn validateRuntimeElemAccess( | ... | @@ -26975,7 +27150,7 @@ fn validateRuntimeElemAccess( |
| 26975 | | 27150 | |
| 26976 | break :msg msg; | 27151 | break :msg msg; |
| 26977 | }; | 27152 | }; |
| 26978 | return sema.failWithOwnedErrorMsg(msg); | 27153 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26979 | } | 27154 | } |
| 26980 | } | 27155 | } |
| 26981 | | 27156 | |
| ... | @@ -27105,7 +27280,7 @@ fn elemValArray( | ... | @@ -27105,7 +27280,7 @@ fn elemValArray( |
| 27105 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 27280 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 27106 | | 27281 | |
| 27107 | if (maybe_index_val) |index_val| { | 27282 | if (maybe_index_val) |index_val| { |
| 27108 | const index = @as(usize, @intCast(index_val.toUnsignedInt(mod))); | 27283 | const index: usize = @intCast(index_val.toUnsignedInt(mod)); |
| 27109 | if (array_sent) |s| { | 27284 | if (array_sent) |s| { |
| 27110 | if (index == array_len) { | 27285 | if (index == array_len) { |
| 27111 | return Air.internedToRef(s.toIntern()); | 27286 | return Air.internedToRef(s.toIntern()); |
| ... | @@ -27121,7 +27296,7 @@ fn elemValArray( | ... | @@ -27121,7 +27296,7 @@ fn elemValArray( |
| 27121 | return mod.undefRef(elem_ty); | 27296 | return mod.undefRef(elem_ty); |
| 27122 | } | 27297 | } |
| 27123 | if (maybe_index_val) |index_val| { | 27298 | if (maybe_index_val) |index_val| { |
| 27124 | const index = @as(usize, @intCast(index_val.toUnsignedInt(mod))); | 27299 | const index: usize = @intCast(index_val.toUnsignedInt(mod)); |
| 27125 | const elem_val = try array_val.elemValue(mod, index); | 27300 | const elem_val = try array_val.elemValue(mod, index); |
| 27126 | return Air.internedToRef(elem_val.toIntern()); | 27301 | return Air.internedToRef(elem_val.toIntern()); |
| 27127 | } | 27302 | } |
| ... | @@ -27234,7 +27409,7 @@ fn elemValSlice( | ... | @@ -27234,7 +27409,7 @@ fn elemValSlice( |
| 27234 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); | 27409 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); |
| 27235 | } | 27410 | } |
| 27236 | if (maybe_index_val) |index_val| { | 27411 | if (maybe_index_val) |index_val| { |
| 27237 | const index = @as(usize, @intCast(index_val.toUnsignedInt(mod))); | 27412 | const index: usize = @intCast(index_val.toUnsignedInt(mod)); |
| 27238 | if (index >= slice_len_s) { | 27413 | if (index >= slice_len_s) { |
| 27239 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; | 27414 | const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else ""; |
| 27240 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); | 27415 | return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label }); |
| ... | @@ -27457,7 +27632,7 @@ fn coerceExtra( | ... | @@ -27457,7 +27632,7 @@ fn coerceExtra( |
| 27457 | | 27632 | |
| 27458 | // Function body to function pointer. | 27633 | // Function body to function pointer. |
| 27459 | if (inst_ty.zigTypeTag(mod) == .Fn) { | 27634 | if (inst_ty.zigTypeTag(mod) == .Fn) { |
| 27460 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 27635 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27461 | const fn_decl = fn_val.pointerDecl(mod).?; | 27636 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 27462 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); | 27637 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 27463 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); | 27638 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | @@ -27706,7 +27881,7 @@ fn coerceExtra( | ... | @@ -27706,7 +27881,7 @@ fn coerceExtra( |
| 27706 | try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); | 27881 | try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); |
| 27707 | break :err_msg err_msg; | 27882 | break :err_msg err_msg; |
| 27708 | }; | 27883 | }; |
| 27709 | return sema.failWithOwnedErrorMsg(err_msg); | 27884 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| 27710 | } | 27885 | } |
| 27711 | return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); | 27886 | return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src); |
| 27712 | }, | 27887 | }, |
| ... | @@ -27746,7 +27921,9 @@ fn coerceExtra( | ... | @@ -27746,7 +27921,9 @@ fn coerceExtra( |
| 27746 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { | 27921 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 27747 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 27922 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 27748 | if (!opts.report_err) return error.NotCoercible; | 27923 | if (!opts.report_err) return error.NotCoercible; |
| 27749 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known"); | 27924 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 27925 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 27926 | }); |
| 27750 | } | 27927 | } |
| 27751 | break :float; | 27928 | break :float; |
| 27752 | }; | 27929 | }; |
| ... | @@ -27777,7 +27954,9 @@ fn coerceExtra( | ... | @@ -27777,7 +27954,9 @@ fn coerceExtra( |
| 27777 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { | 27954 | if (dest_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 27778 | if (!opts.report_err) return error.NotCoercible; | 27955 | if (!opts.report_err) return error.NotCoercible; |
| 27779 | if (opts.no_cast_to_comptime_int) return inst; | 27956 | if (opts.no_cast_to_comptime_int) return inst; |
| 27780 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known"); | 27957 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 27958 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", |
| | 27959 | }); |
| 27781 | } | 27960 | } |
| 27782 | | 27961 | |
| 27783 | // integer widening | 27962 | // integer widening |
| ... | @@ -27798,7 +27977,7 @@ fn coerceExtra( | ... | @@ -27798,7 +27977,7 @@ fn coerceExtra( |
| 27798 | }, | 27977 | }, |
| 27799 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) { | 27978 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) { |
| 27800 | .ComptimeFloat => { | 27979 | .ComptimeFloat => { |
| 27801 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 27980 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27802 | const result_val = try val.floatCast(dest_ty, mod); | 27981 | const result_val = try val.floatCast(dest_ty, mod); |
| 27803 | return Air.internedToRef(result_val.toIntern()); | 27982 | return Air.internedToRef(result_val.toIntern()); |
| 27804 | }, | 27983 | }, |
| ... | @@ -27819,7 +27998,9 @@ fn coerceExtra( | ... | @@ -27819,7 +27998,9 @@ fn coerceExtra( |
| 27819 | return Air.internedToRef(result_val.toIntern()); | 27998 | return Air.internedToRef(result_val.toIntern()); |
| 27820 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 27999 | } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 27821 | if (!opts.report_err) return error.NotCoercible; | 28000 | if (!opts.report_err) return error.NotCoercible; |
| 27822 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); | 28001 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 28002 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 28003 | }); |
| 27823 | } | 28004 | } |
| 27824 | | 28005 | |
| 27825 | // float widening | 28006 | // float widening |
| ... | @@ -27837,7 +28018,9 @@ fn coerceExtra( | ... | @@ -27837,7 +28018,9 @@ fn coerceExtra( |
| 27837 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { | 28018 | const val = (try sema.resolveMaybeUndefVal(inst)) orelse { |
| 27838 | if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { | 28019 | if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 27839 | if (!opts.report_err) return error.NotCoercible; | 28020 | if (!opts.report_err) return error.NotCoercible; |
| 27840 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known"); | 28021 | return sema.failWithNeededComptime(block, inst_src, .{ |
| | 28022 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", |
| | 28023 | }); |
| 27841 | } | 28024 | } |
| 27842 | break :int; | 28025 | break :int; |
| 27843 | }; | 28026 | }; |
| ... | @@ -27862,7 +28045,7 @@ fn coerceExtra( | ... | @@ -27862,7 +28045,7 @@ fn coerceExtra( |
| 27862 | .Enum => switch (inst_ty.zigTypeTag(mod)) { | 28045 | .Enum => switch (inst_ty.zigTypeTag(mod)) { |
| 27863 | .EnumLiteral => { | 28046 | .EnumLiteral => { |
| 27864 | // enum literal to enum | 28047 | // enum literal to enum |
| 27865 | const val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 28048 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27866 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; | 28049 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 27867 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { | 28050 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { |
| 27868 | const msg = msg: { | 28051 | const msg = msg: { |
| ... | @@ -27876,9 +28059,9 @@ fn coerceExtra( | ... | @@ -27876,9 +28059,9 @@ fn coerceExtra( |
| 27876 | try sema.addDeclaredHereNote(msg, dest_ty); | 28059 | try sema.addDeclaredHereNote(msg, dest_ty); |
| 27877 | break :msg msg; | 28060 | break :msg msg; |
| 27878 | }; | 28061 | }; |
| 27879 | return sema.failWithOwnedErrorMsg(msg); | 28062 | return sema.failWithOwnedErrorMsg(block, msg); |
| 27880 | }; | 28063 | }; |
| 27881 | return Air.internedToRef((try mod.enumValueFieldIndex(dest_ty, @as(u32, @intCast(field_index)))).toIntern()); | 28064 | return Air.internedToRef((try mod.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern()); |
| 27882 | }, | 28065 | }, |
| 27883 | .Union => blk: { | 28066 | .Union => blk: { |
| 27884 | // union to its own tag type | 28067 | // union to its own tag type |
| ... | @@ -28007,7 +28190,7 @@ fn coerceExtra( | ... | @@ -28007,7 +28190,7 @@ fn coerceExtra( |
| 28007 | try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{}); | 28190 | try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{}); |
| 28008 | break :msg msg; | 28191 | break :msg msg; |
| 28009 | }; | 28192 | }; |
| 28010 | return sema.failWithOwnedErrorMsg(msg); | 28193 | return sema.failWithOwnedErrorMsg(block, msg); |
| 28011 | } | 28194 | } |
| 28012 | | 28195 | |
| 28013 | const msg = msg: { | 28196 | const msg = msg: { |
| ... | @@ -28053,7 +28236,7 @@ fn coerceExtra( | ... | @@ -28053,7 +28236,7 @@ fn coerceExtra( |
| 28053 | | 28236 | |
| 28054 | break :msg msg; | 28237 | break :msg msg; |
| 28055 | }; | 28238 | }; |
| 28056 | return sema.failWithOwnedErrorMsg(msg); | 28239 | return sema.failWithOwnedErrorMsg(block, msg); |
| 28057 | } | 28240 | } |
| 28058 | | 28241 | |
| 28059 | fn coerceInMemory( | 28242 | fn coerceInMemory( |
| ... | @@ -28282,8 +28465,8 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -28282,8 +28465,8 @@ const InMemoryCoercionResult = union(enum) { |
| 28282 | var index: u6 = 0; | 28465 | var index: u6 = 0; |
| 28283 | var actual_noalias = false; | 28466 | var actual_noalias = false; |
| 28284 | while (true) : (index += 1) { | 28467 | while (true) : (index += 1) { |
| 28285 | const actual = @as(u1, @truncate(param.actual >> index)); | 28468 | const actual: u1 = @truncate(param.actual >> index); |
| 28286 | const wanted = @as(u1, @truncate(param.wanted >> index)); | 28469 | const wanted: u1 = @truncate(param.wanted >> index); |
| 28287 | if (actual != wanted) { | 28470 | if (actual != wanted) { |
| 28288 | actual_noalias = actual == 1; | 28471 | actual_noalias = actual == 1; |
| 28289 | break; | 28472 | break; |
| ... | @@ -28998,7 +29181,7 @@ fn coerceVarArgParam( | ... | @@ -28998,7 +29181,7 @@ fn coerceVarArgParam( |
| 28998 | .{}, | 29181 | .{}, |
| 28999 | ), | 29182 | ), |
| 29000 | .Fn => blk: { | 29183 | .Fn => blk: { |
| 29001 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, ""); | 29184 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 29002 | const fn_decl = fn_val.pointerDecl(mod).?; | 29185 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 29003 | break :blk try sema.analyzeDeclRef(fn_decl); | 29186 | break :blk try sema.analyzeDeclRef(fn_decl); |
| 29004 | }, | 29187 | }, |
| ... | @@ -29029,7 +29212,7 @@ fn coerceVarArgParam( | ... | @@ -29029,7 +29212,7 @@ fn coerceVarArgParam( |
| 29029 | try sema.addDeclaredHereNote(msg, coerced_ty); | 29212 | try sema.addDeclaredHereNote(msg, coerced_ty); |
| 29030 | break :msg msg; | 29213 | break :msg msg; |
| 29031 | }; | 29214 | }; |
| 29032 | return sema.failWithOwnedErrorMsg(msg); | 29215 | return sema.failWithOwnedErrorMsg(block, msg); |
| 29033 | } | 29216 | } |
| 29034 | return coerced; | 29217 | return coerced; |
| 29035 | } | 29218 | } |
| ... | @@ -29446,7 +29629,7 @@ fn beginComptimePtrMutation( | ... | @@ -29446,7 +29629,7 @@ fn beginComptimePtrMutation( |
| 29446 | // bytes.len may be one greater than dest_len because of the case when | 29629 | // bytes.len may be one greater than dest_len because of the case when |
| 29447 | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. | 29630 | // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted. |
| 29448 | assert(bytes.len >= dest_len); | 29631 | assert(bytes.len >= dest_len); |
| 29449 | const elems = try arena.alloc(Value, @as(usize, @intCast(dest_len))); | 29632 | const elems = try arena.alloc(Value, @intCast(dest_len)); |
| 29450 | for (elems, 0..) |*elem, i| { | 29633 | for (elems, 0..) |*elem, i| { |
| 29451 | elem.* = try mod.intValue(elem_ty, bytes[i]); | 29634 | elem.* = try mod.intValue(elem_ty, bytes[i]); |
| 29452 | } | 29635 | } |
| ... | @@ -29458,7 +29641,7 @@ fn beginComptimePtrMutation( | ... | @@ -29458,7 +29641,7 @@ fn beginComptimePtrMutation( |
| 29458 | block, | 29641 | block, |
| 29459 | src, | 29642 | src, |
| 29460 | elem_ty, | 29643 | elem_ty, |
| 29461 | &elems[@as(usize, @intCast(elem_ptr.index))], | 29644 | &elems[@intCast(elem_ptr.index)], |
| 29462 | ptr_elem_ty, | 29645 | ptr_elem_ty, |
| 29463 | parent.mut_decl, | 29646 | parent.mut_decl, |
| 29464 | ); | 29647 | ); |
| ... | @@ -29486,7 +29669,7 @@ fn beginComptimePtrMutation( | ... | @@ -29486,7 +29669,7 @@ fn beginComptimePtrMutation( |
| 29486 | block, | 29669 | block, |
| 29487 | src, | 29670 | src, |
| 29488 | elem_ty, | 29671 | elem_ty, |
| 29489 | &elems[@as(usize, @intCast(elem_ptr.index))], | 29672 | &elems[@intCast(elem_ptr.index)], |
| 29490 | ptr_elem_ty, | 29673 | ptr_elem_ty, |
| 29491 | parent.mut_decl, | 29674 | parent.mut_decl, |
| 29492 | ); | 29675 | ); |
| ... | @@ -29497,7 +29680,7 @@ fn beginComptimePtrMutation( | ... | @@ -29497,7 +29680,7 @@ fn beginComptimePtrMutation( |
| 29497 | block, | 29680 | block, |
| 29498 | src, | 29681 | src, |
| 29499 | elem_ty, | 29682 | elem_ty, |
| 29500 | &val_ptr.castTag(.aggregate).?.data[@as(usize, @intCast(elem_ptr.index))], | 29683 | &val_ptr.castTag(.aggregate).?.data[@intCast(elem_ptr.index)], |
| 29501 | ptr_elem_ty, | 29684 | ptr_elem_ty, |
| 29502 | parent.mut_decl, | 29685 | parent.mut_decl, |
| 29503 | ), | 29686 | ), |
| ... | @@ -29523,7 +29706,7 @@ fn beginComptimePtrMutation( | ... | @@ -29523,7 +29706,7 @@ fn beginComptimePtrMutation( |
| 29523 | block, | 29706 | block, |
| 29524 | src, | 29707 | src, |
| 29525 | elem_ty, | 29708 | elem_ty, |
| 29526 | &elems[@as(usize, @intCast(elem_ptr.index))], | 29709 | &elems[@intCast(elem_ptr.index)], |
| 29527 | ptr_elem_ty, | 29710 | ptr_elem_ty, |
| 29528 | parent.mut_decl, | 29711 | parent.mut_decl, |
| 29529 | ); | 29712 | ); |
| ... | @@ -29578,7 +29761,7 @@ fn beginComptimePtrMutation( | ... | @@ -29578,7 +29761,7 @@ fn beginComptimePtrMutation( |
| 29578 | }, | 29761 | }, |
| 29579 | .field => |field_ptr| { | 29762 | .field => |field_ptr| { |
| 29580 | const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod); | 29763 | const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod); |
| 29581 | const field_index = @as(u32, @intCast(field_ptr.index)); | 29764 | const field_index: u32 = @intCast(field_ptr.index); |
| 29582 | | 29765 | |
| 29583 | var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty); | 29766 | var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty); |
| 29584 | switch (parent.pointee) { | 29767 | switch (parent.pointee) { |
| ... | @@ -30015,12 +30198,12 @@ fn beginComptimePtrLoad( | ... | @@ -30015,12 +30198,12 @@ fn beginComptimePtrLoad( |
| 30015 | } | 30198 | } |
| 30016 | deref.pointee = TypedValue{ | 30199 | deref.pointee = TypedValue{ |
| 30017 | .ty = elem_ty, | 30200 | .ty = elem_ty, |
| 30018 | .val = try array_tv.val.elemValue(mod, @as(usize, @intCast(elem_ptr.index))), | 30201 | .val = try array_tv.val.elemValue(mod, @intCast(elem_ptr.index)), |
| 30019 | }; | 30202 | }; |
| 30020 | break :blk deref; | 30203 | break :blk deref; |
| 30021 | }, | 30204 | }, |
| 30022 | .field => |field_ptr| blk: { | 30205 | .field => |field_ptr| blk: { |
| 30023 | const field_index = @as(u32, @intCast(field_ptr.index)); | 30206 | const field_index: u32 = @intCast(field_ptr.index); |
| 30024 | const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod); | 30207 | const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod); |
| 30025 | var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty); | 30208 | var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty); |
| 30026 | | 30209 | |
| ... | @@ -30284,7 +30467,7 @@ fn coerceEnumToUnion( | ... | @@ -30284,7 +30467,7 @@ fn coerceEnumToUnion( |
| 30284 | try sema.addDeclaredHereNote(msg, union_ty); | 30467 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30285 | break :msg msg; | 30468 | break :msg msg; |
| 30286 | }; | 30469 | }; |
| 30287 | return sema.failWithOwnedErrorMsg(msg); | 30470 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30288 | }; | 30471 | }; |
| 30289 | | 30472 | |
| 30290 | const enum_tag = try sema.coerce(block, tag_ty, inst, inst_src); | 30473 | const enum_tag = try sema.coerce(block, tag_ty, inst, inst_src); |
| ... | @@ -30298,7 +30481,7 @@ fn coerceEnumToUnion( | ... | @@ -30298,7 +30481,7 @@ fn coerceEnumToUnion( |
| 30298 | try sema.addDeclaredHereNote(msg, union_ty); | 30481 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30299 | break :msg msg; | 30482 | break :msg msg; |
| 30300 | }; | 30483 | }; |
| 30301 | return sema.failWithOwnedErrorMsg(msg); | 30484 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30302 | }; | 30485 | }; |
| 30303 | | 30486 | |
| 30304 | const union_obj = mod.typeToUnion(union_ty).?; | 30487 | const union_obj = mod.typeToUnion(union_ty).?; |
| ... | @@ -30316,7 +30499,7 @@ fn coerceEnumToUnion( | ... | @@ -30316,7 +30499,7 @@ fn coerceEnumToUnion( |
| 30316 | try sema.addDeclaredHereNote(msg, union_ty); | 30499 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30317 | break :msg msg; | 30500 | break :msg msg; |
| 30318 | }; | 30501 | }; |
| 30319 | return sema.failWithOwnedErrorMsg(msg); | 30502 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30320 | } | 30503 | } |
| 30321 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { | 30504 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 30322 | const msg = msg: { | 30505 | const msg = msg: { |
| ... | @@ -30333,7 +30516,7 @@ fn coerceEnumToUnion( | ... | @@ -30333,7 +30516,7 @@ fn coerceEnumToUnion( |
| 30333 | try sema.addDeclaredHereNote(msg, union_ty); | 30516 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30334 | break :msg msg; | 30517 | break :msg msg; |
| 30335 | }; | 30518 | }; |
| 30336 | return sema.failWithOwnedErrorMsg(msg); | 30519 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30337 | }; | 30520 | }; |
| 30338 | | 30521 | |
| 30339 | return Air.internedToRef((try mod.unionValue(union_ty, val, opv)).toIntern()); | 30522 | return Air.internedToRef((try mod.unionValue(union_ty, val, opv)).toIntern()); |
| ... | @@ -30350,7 +30533,7 @@ fn coerceEnumToUnion( | ... | @@ -30350,7 +30533,7 @@ fn coerceEnumToUnion( |
| 30350 | try sema.addDeclaredHereNote(msg, tag_ty); | 30533 | try sema.addDeclaredHereNote(msg, tag_ty); |
| 30351 | break :msg msg; | 30534 | break :msg msg; |
| 30352 | }; | 30535 | }; |
| 30353 | return sema.failWithOwnedErrorMsg(msg); | 30536 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30354 | } | 30537 | } |
| 30355 | | 30538 | |
| 30356 | const union_obj = mod.typeToUnion(union_ty).?; | 30539 | const union_obj = mod.typeToUnion(union_ty).?; |
| ... | @@ -30374,7 +30557,7 @@ fn coerceEnumToUnion( | ... | @@ -30374,7 +30557,7 @@ fn coerceEnumToUnion( |
| 30374 | if (msg) |some| { | 30557 | if (msg) |some| { |
| 30375 | msg = null; | 30558 | msg = null; |
| 30376 | try sema.addDeclaredHereNote(some, union_ty); | 30559 | try sema.addDeclaredHereNote(some, union_ty); |
| 30377 | return sema.failWithOwnedErrorMsg(some); | 30560 | return sema.failWithOwnedErrorMsg(block, some); |
| 30378 | } | 30561 | } |
| 30379 | } | 30562 | } |
| 30380 | | 30563 | |
| ... | @@ -30404,7 +30587,7 @@ fn coerceEnumToUnion( | ... | @@ -30404,7 +30587,7 @@ fn coerceEnumToUnion( |
| 30404 | try sema.addDeclaredHereNote(msg, union_ty); | 30587 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30405 | break :msg msg; | 30588 | break :msg msg; |
| 30406 | }; | 30589 | }; |
| 30407 | return sema.failWithOwnedErrorMsg(msg); | 30590 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30408 | } | 30591 | } |
| 30409 | | 30592 | |
| 30410 | fn coerceAnonStructToUnion( | 30593 | fn coerceAnonStructToUnion( |
| ... | @@ -30461,7 +30644,7 @@ fn coerceAnonStructToUnion( | ... | @@ -30461,7 +30644,7 @@ fn coerceAnonStructToUnion( |
| 30461 | try sema.addDeclaredHereNote(msg, union_ty); | 30644 | try sema.addDeclaredHereNote(msg, union_ty); |
| 30462 | break :msg msg; | 30645 | break :msg msg; |
| 30463 | }; | 30646 | }; |
| 30464 | return sema.failWithOwnedErrorMsg(msg); | 30647 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30465 | }, | 30648 | }, |
| 30466 | } | 30649 | } |
| 30467 | } | 30650 | } |
| ... | @@ -30533,7 +30716,7 @@ fn coerceArrayLike( | ... | @@ -30533,7 +30716,7 @@ fn coerceArrayLike( |
| 30533 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 30716 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 30534 | break :msg msg; | 30717 | break :msg msg; |
| 30535 | }; | 30718 | }; |
| 30536 | return sema.failWithOwnedErrorMsg(msg); | 30719 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30537 | } | 30720 | } |
| 30538 | | 30721 | |
| 30539 | const dest_elem_ty = dest_ty.childType(mod); | 30722 | const dest_elem_ty = dest_ty.childType(mod); |
| ... | @@ -30592,7 +30775,7 @@ fn coerceTupleToArray( | ... | @@ -30592,7 +30775,7 @@ fn coerceTupleToArray( |
| 30592 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 30775 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 30593 | break :msg msg; | 30776 | break :msg msg; |
| 30594 | }; | 30777 | }; |
| 30595 | return sema.failWithOwnedErrorMsg(msg); | 30778 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30596 | } | 30779 | } |
| 30597 | | 30780 | |
| 30598 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len); | 30781 | const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len); |
| ... | @@ -30602,7 +30785,7 @@ fn coerceTupleToArray( | ... | @@ -30602,7 +30785,7 @@ fn coerceTupleToArray( |
| 30602 | | 30785 | |
| 30603 | var runtime_src: ?LazySrcLoc = null; | 30786 | var runtime_src: ?LazySrcLoc = null; |
| 30604 | for (element_vals, element_refs, 0..) |*val, *ref, i_usize| { | 30787 | for (element_vals, element_refs, 0..) |*val, *ref, i_usize| { |
| 30605 | const i = @as(u32, @intCast(i_usize)); | 30788 | const i: u32 = @intCast(i_usize); |
| 30606 | if (i_usize == inst_len) { | 30789 | if (i_usize == inst_len) { |
| 30607 | const sentinel_val = dest_ty.sentinel(mod).?; | 30790 | const sentinel_val = dest_ty.sentinel(mod).?; |
| 30608 | val.* = sentinel_val.toIntern(); | 30791 | val.* = sentinel_val.toIntern(); |
| ... | @@ -30713,7 +30896,7 @@ fn coerceTupleToStruct( | ... | @@ -30713,7 +30896,7 @@ fn coerceTupleToStruct( |
| 30713 | else => unreachable, | 30896 | else => unreachable, |
| 30714 | }; | 30897 | }; |
| 30715 | for (0..field_count) |field_index_usize| { | 30898 | for (0..field_count) |field_index_usize| { |
| 30716 | const field_i = @as(u32, @intCast(field_index_usize)); | 30899 | const field_i: u32 = @intCast(field_index_usize); |
| 30717 | const field_src = inst_src; // TODO better source location | 30900 | const field_src = inst_src; // TODO better source location |
| 30718 | // https://github.com/ziglang/zig/issues/15709 | 30901 | // https://github.com/ziglang/zig/issues/15709 |
| 30719 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { | 30902 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| ... | @@ -30731,7 +30914,9 @@ fn coerceTupleToStruct( | ... | @@ -30731,7 +30914,9 @@ fn coerceTupleToStruct( |
| 30731 | field_refs[field_index] = coerced; | 30914 | field_refs[field_index] = coerced; |
| 30732 | if (field.is_comptime) { | 30915 | if (field.is_comptime) { |
| 30733 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { | 30916 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 30734 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 30917 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 30918 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 30919 | }); |
| 30735 | }; | 30920 | }; |
| 30736 | | 30921 | |
| 30737 | if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) { | 30922 | if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) { |
| ... | @@ -30777,7 +30962,7 @@ fn coerceTupleToStruct( | ... | @@ -30777,7 +30962,7 @@ fn coerceTupleToStruct( |
| 30777 | if (root_msg) |msg| { | 30962 | if (root_msg) |msg| { |
| 30778 | try sema.addDeclaredHereNote(msg, struct_ty); | 30963 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 30779 | root_msg = null; | 30964 | root_msg = null; |
| 30780 | return sema.failWithOwnedErrorMsg(msg); | 30965 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30781 | } | 30966 | } |
| 30782 | | 30967 | |
| 30783 | if (runtime_src) |rs| { | 30968 | if (runtime_src) |rs| { |
| ... | @@ -30829,7 +31014,7 @@ fn coerceTupleToTuple( | ... | @@ -30829,7 +31014,7 @@ fn coerceTupleToTuple( |
| 30829 | | 31014 | |
| 30830 | var runtime_src: ?LazySrcLoc = null; | 31015 | var runtime_src: ?LazySrcLoc = null; |
| 30831 | for (0..dest_field_count) |field_index_usize| { | 31016 | for (0..dest_field_count) |field_index_usize| { |
| 30832 | const field_i = @as(u32, @intCast(field_index_usize)); | 31017 | const field_i: u32 = @intCast(field_index_usize); |
| 30833 | const field_src = inst_src; // TODO better source location | 31018 | const field_src = inst_src; // TODO better source location |
| 30834 | // https://github.com/ziglang/zig/issues/15709 | 31019 | // https://github.com/ziglang/zig/issues/15709 |
| 30835 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { | 31020 | const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) { |
| ... | @@ -30862,7 +31047,9 @@ fn coerceTupleToTuple( | ... | @@ -30862,7 +31047,9 @@ fn coerceTupleToTuple( |
| 30862 | field_refs[field_index] = coerced; | 31047 | field_refs[field_index] = coerced; |
| 30863 | if (default_val != .none) { | 31048 | if (default_val != .none) { |
| 30864 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { | 31049 | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 30865 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 31050 | return sema.failWithNeededComptime(block, field_src, .{ |
| | 31051 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| | 31052 | }); |
| 30866 | }; | 31053 | }; |
| 30867 | | 31054 | |
| 30868 | if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) { | 31055 | if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) { |
| ... | @@ -30921,7 +31108,7 @@ fn coerceTupleToTuple( | ... | @@ -30921,7 +31108,7 @@ fn coerceTupleToTuple( |
| 30921 | if (root_msg) |msg| { | 31108 | if (root_msg) |msg| { |
| 30922 | try sema.addDeclaredHereNote(msg, tuple_ty); | 31109 | try sema.addDeclaredHereNote(msg, tuple_ty); |
| 30923 | root_msg = null; | 31110 | root_msg = null; |
| 30924 | return sema.failWithOwnedErrorMsg(msg); | 31111 | return sema.failWithOwnedErrorMsg(block, msg); |
| 30925 | } | 31112 | } |
| 30926 | | 31113 | |
| 30927 | if (runtime_src) |rs| { | 31114 | if (runtime_src) |rs| { |
| ... | @@ -30982,7 +31169,7 @@ fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void { | ... | @@ -30982,7 +31169,7 @@ fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void { |
| 30982 | const decl = mod.declPtr(decl_index); | 31169 | const decl = mod.declPtr(decl_index); |
| 30983 | if (decl.analysis == .in_progress) { | 31170 | if (decl.analysis == .in_progress) { |
| 30984 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{}); | 31171 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{}); |
| 30985 | return sema.failWithOwnedErrorMsg(msg); | 31172 | return sema.failWithOwnedErrorMsg(null, msg); |
| 30986 | } | 31173 | } |
| 30987 | | 31174 | |
| 30988 | mod.ensureDeclAnalyzed(decl_index) catch |err| { | 31175 | mod.ensureDeclAnalyzed(decl_index) catch |err| { |
| ... | @@ -31217,14 +31404,10 @@ fn analyzeIsNull( | ... | @@ -31217,14 +31404,10 @@ fn analyzeIsNull( |
| 31217 | } | 31404 | } |
| 31218 | const is_null = opt_val.isNull(mod); | 31405 | const is_null = opt_val.isNull(mod); |
| 31219 | const bool_value = if (invert_logic) !is_null else is_null; | 31406 | const bool_value = if (invert_logic) !is_null else is_null; |
| 31220 | if (bool_value) { | 31407 | return if (bool_value) .bool_true else .bool_false; |
| 31221 | return Air.Inst.Ref.bool_true; | | |
| 31222 | } else { | | |
| 31223 | return Air.Inst.Ref.bool_false; | | |
| 31224 | } | | |
| 31225 | } | 31408 | } |
| 31226 | | 31409 | |
| 31227 | const inverted_non_null_res = if (invert_logic) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 31410 | const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false; |
| 31228 | const operand_ty = sema.typeOf(operand); | 31411 | const operand_ty = sema.typeOf(operand); |
| 31229 | if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) { | 31412 | if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) { |
| 31230 | return inverted_non_null_res; | 31413 | return inverted_non_null_res; |
| ... | @@ -31249,14 +31432,14 @@ fn analyzePtrIsNonErrComptimeOnly( | ... | @@ -31249,14 +31432,14 @@ fn analyzePtrIsNonErrComptimeOnly( |
| 31249 | const child_ty = ptr_ty.childType(mod); | 31432 | const child_ty = ptr_ty.childType(mod); |
| 31250 | | 31433 | |
| 31251 | const child_tag = child_ty.zigTypeTag(mod); | 31434 | const child_tag = child_ty.zigTypeTag(mod); |
| 31252 | if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return Air.Inst.Ref.bool_true; | 31435 | if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true; |
| 31253 | if (child_tag == .ErrorSet) return Air.Inst.Ref.bool_false; | 31436 | if (child_tag == .ErrorSet) return .bool_false; |
| 31254 | assert(child_tag == .ErrorUnion); | 31437 | assert(child_tag == .ErrorUnion); |
| 31255 | | 31438 | |
| 31256 | _ = block; | 31439 | _ = block; |
| 31257 | _ = src; | 31440 | _ = src; |
| 31258 | | 31441 | |
| 31259 | return Air.Inst.Ref.none; | 31442 | return .none; |
| 31260 | } | 31443 | } |
| 31261 | | 31444 | |
| 31262 | fn analyzeIsNonErrComptimeOnly( | 31445 | fn analyzeIsNonErrComptimeOnly( |
| ... | @@ -31606,7 +31789,9 @@ fn analyzeSlice( | ... | @@ -31606,7 +31789,9 @@ fn analyzeSlice( |
| 31606 | const sentinel = s: { | 31789 | const sentinel = s: { |
| 31607 | if (sentinel_opt != .none) { | 31790 | if (sentinel_opt != .none) { |
| 31608 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); | 31791 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 31609 | break :s try sema.resolveConstValue(block, sentinel_src, casted, "slice sentinel must be comptime-known"); | 31792 | break :s try sema.resolveConstValue(block, sentinel_src, casted, .{ |
| | 31793 | .needed_comptime_reason = "slice sentinel must be comptime-known", |
| | 31794 | }); |
| 31610 | } | 31795 | } |
| 31611 | // If we are slicing to the end of something that is sentinel-terminated | 31796 | // If we are slicing to the end of something that is sentinel-terminated |
| 31612 | // then the resulting slice type is also sentinel-terminated. | 31797 | // then the resulting slice type is also sentinel-terminated. |
| ... | @@ -31676,7 +31861,7 @@ fn analyzeSlice( | ... | @@ -31676,7 +31861,7 @@ fn analyzeSlice( |
| 31676 | | 31861 | |
| 31677 | break :msg msg; | 31862 | break :msg msg; |
| 31678 | }; | 31863 | }; |
| 31679 | return sema.failWithOwnedErrorMsg(msg); | 31864 | return sema.failWithOwnedErrorMsg(block, msg); |
| 31680 | } | 31865 | } |
| 31681 | } else { | 31866 | } else { |
| 31682 | runtime_src = ptr_src; | 31867 | runtime_src = ptr_src; |
| ... | @@ -31878,11 +32063,11 @@ fn cmpNumeric( | ... | @@ -31878,11 +32063,11 @@ fn cmpNumeric( |
| 31878 | // Compare ints: const vs. undefined (or vice versa) | 32063 | // Compare ints: const vs. undefined (or vice versa) |
| 31879 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) { | 32064 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) { |
| 31880 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| { | 32065 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| { |
| 31881 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 32066 | return if (res) .bool_true else .bool_false; |
| 31882 | } | 32067 | } |
| 31883 | } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) { | 32068 | } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) { |
| 31884 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| { | 32069 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| { |
| 31885 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 32070 | return if (res) .bool_true else .bool_false; |
| 31886 | } | 32071 | } |
| 31887 | } | 32072 | } |
| 31888 | | 32073 | |
| ... | @@ -31890,22 +32075,17 @@ fn cmpNumeric( | ... | @@ -31890,22 +32075,17 @@ fn cmpNumeric( |
| 31890 | return mod.undefRef(Type.bool); | 32075 | return mod.undefRef(Type.bool); |
| 31891 | } | 32076 | } |
| 31892 | if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) { | 32077 | if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) { |
| 31893 | if (op == std.math.CompareOperator.neq) { | 32078 | return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false; |
| 31894 | return Air.Inst.Ref.bool_true; | | |
| 31895 | } else { | | |
| 31896 | return Air.Inst.Ref.bool_false; | | |
| 31897 | } | | |
| 31898 | } | | |
| 31899 | if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema)) { | | |
| 31900 | return Air.Inst.Ref.bool_true; | | |
| 31901 | } else { | | |
| 31902 | return Air.Inst.Ref.bool_false; | | |
| 31903 | } | 32079 | } |
| | 32080 | return if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema)) |
| | 32081 | .bool_true |
| | 32082 | else |
| | 32083 | .bool_false; |
| 31904 | } else { | 32084 | } else { |
| 31905 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) { | 32085 | if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) { |
| 31906 | // Compare ints: const vs. var | 32086 | // Compare ints: const vs. var |
| 31907 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| { | 32087 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| { |
| 31908 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 32088 | return if (res) .bool_true else .bool_false; |
| 31909 | } | 32089 | } |
| 31910 | } | 32090 | } |
| 31911 | break :src rhs_src; | 32091 | break :src rhs_src; |
| ... | @@ -31915,7 +32095,7 @@ fn cmpNumeric( | ... | @@ -31915,7 +32095,7 @@ fn cmpNumeric( |
| 31915 | if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) { | 32095 | if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) { |
| 31916 | // Compare ints: var vs. const | 32096 | // Compare ints: var vs. const |
| 31917 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| { | 32097 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| { |
| 31918 | return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false; | 32098 | return if (res) .bool_true else .bool_false; |
| 31919 | } | 32099 | } |
| 31920 | } | 32100 | } |
| 31921 | } | 32101 | } |
| ... | @@ -31982,34 +32162,34 @@ fn cmpNumeric( | ... | @@ -31982,34 +32162,34 @@ fn cmpNumeric( |
| 31982 | if (lhs_val.isUndef(mod)) | 32162 | if (lhs_val.isUndef(mod)) |
| 31983 | return mod.undefRef(Type.bool); | 32163 | return mod.undefRef(Type.bool); |
| 31984 | if (lhs_val.isNan(mod)) switch (op) { | 32164 | if (lhs_val.isNan(mod)) switch (op) { |
| 31985 | .neq => return Air.Inst.Ref.bool_true, | 32165 | .neq => return .bool_true, |
| 31986 | else => return Air.Inst.Ref.bool_false, | 32166 | else => return .bool_false, |
| 31987 | }; | 32167 | }; |
| 31988 | if (lhs_val.isInf(mod)) switch (op) { | 32168 | if (lhs_val.isInf(mod)) switch (op) { |
| 31989 | .neq => return Air.Inst.Ref.bool_true, | 32169 | .neq => return .bool_true, |
| 31990 | .eq => return Air.Inst.Ref.bool_false, | 32170 | .eq => return .bool_false, |
| 31991 | .gt, .gte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true, | 32171 | .gt, .gte => return if (lhs_val.isNegativeInf(mod)) .bool_false else .bool_true, |
| 31992 | .lt, .lte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false, | 32172 | .lt, .lte => return if (lhs_val.isNegativeInf(mod)) .bool_true else .bool_false, |
| 31993 | }; | 32173 | }; |
| 31994 | if (!rhs_is_signed) { | 32174 | if (!rhs_is_signed) { |
| 31995 | switch (lhs_val.orderAgainstZero(mod)) { | 32175 | switch (lhs_val.orderAgainstZero(mod)) { |
| 31996 | .gt => {}, | 32176 | .gt => {}, |
| 31997 | .eq => switch (op) { // LHS = 0, RHS is unsigned | 32177 | .eq => switch (op) { // LHS = 0, RHS is unsigned |
| 31998 | .lte => return Air.Inst.Ref.bool_true, | 32178 | .lte => return .bool_true, |
| 31999 | .gt => return Air.Inst.Ref.bool_false, | 32179 | .gt => return .bool_false, |
| 32000 | else => {}, | 32180 | else => {}, |
| 32001 | }, | 32181 | }, |
| 32002 | .lt => switch (op) { // LHS < 0, RHS is unsigned | 32182 | .lt => switch (op) { // LHS < 0, RHS is unsigned |
| 32003 | .neq, .lt, .lte => return Air.Inst.Ref.bool_true, | 32183 | .neq, .lt, .lte => return .bool_true, |
| 32004 | .eq, .gt, .gte => return Air.Inst.Ref.bool_false, | 32184 | .eq, .gt, .gte => return .bool_false, |
| 32005 | }, | 32185 | }, |
| 32006 | } | 32186 | } |
| 32007 | } | 32187 | } |
| 32008 | if (lhs_is_float) { | 32188 | if (lhs_is_float) { |
| 32009 | if (lhs_val.floatHasFraction(mod)) { | 32189 | if (lhs_val.floatHasFraction(mod)) { |
| 32010 | switch (op) { | 32190 | switch (op) { |
| 32011 | .eq => return Air.Inst.Ref.bool_false, | 32191 | .eq => return .bool_false, |
| 32012 | .neq => return Air.Inst.Ref.bool_true, | 32192 | .neq => return .bool_true, |
| 32013 | else => {}, | 32193 | else => {}, |
| 32014 | } | 32194 | } |
| 32015 | } | 32195 | } |
| ... | @@ -32040,34 +32220,34 @@ fn cmpNumeric( | ... | @@ -32040,34 +32220,34 @@ fn cmpNumeric( |
| 32040 | if (rhs_val.isUndef(mod)) | 32220 | if (rhs_val.isUndef(mod)) |
| 32041 | return mod.undefRef(Type.bool); | 32221 | return mod.undefRef(Type.bool); |
| 32042 | if (rhs_val.isNan(mod)) switch (op) { | 32222 | if (rhs_val.isNan(mod)) switch (op) { |
| 32043 | .neq => return Air.Inst.Ref.bool_true, | 32223 | .neq => return .bool_true, |
| 32044 | else => return Air.Inst.Ref.bool_false, | 32224 | else => return .bool_false, |
| 32045 | }; | 32225 | }; |
| 32046 | if (rhs_val.isInf(mod)) switch (op) { | 32226 | if (rhs_val.isInf(mod)) switch (op) { |
| 32047 | .neq => return Air.Inst.Ref.bool_true, | 32227 | .neq => return .bool_true, |
| 32048 | .eq => return Air.Inst.Ref.bool_false, | 32228 | .eq => return .bool_false, |
| 32049 | .gt, .gte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false, | 32229 | .gt, .gte => return if (rhs_val.isNegativeInf(mod)) .bool_true else .bool_false, |
| 32050 | .lt, .lte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true, | 32230 | .lt, .lte => return if (rhs_val.isNegativeInf(mod)) .bool_false else .bool_true, |
| 32051 | }; | 32231 | }; |
| 32052 | if (!lhs_is_signed) { | 32232 | if (!lhs_is_signed) { |
| 32053 | switch (rhs_val.orderAgainstZero(mod)) { | 32233 | switch (rhs_val.orderAgainstZero(mod)) { |
| 32054 | .gt => {}, | 32234 | .gt => {}, |
| 32055 | .eq => switch (op) { // RHS = 0, LHS is unsigned | 32235 | .eq => switch (op) { // RHS = 0, LHS is unsigned |
| 32056 | .gte => return Air.Inst.Ref.bool_true, | 32236 | .gte => return .bool_true, |
| 32057 | .lt => return Air.Inst.Ref.bool_false, | 32237 | .lt => return .bool_false, |
| 32058 | else => {}, | 32238 | else => {}, |
| 32059 | }, | 32239 | }, |
| 32060 | .lt => switch (op) { // RHS < 0, LHS is unsigned | 32240 | .lt => switch (op) { // RHS < 0, LHS is unsigned |
| 32061 | .neq, .gt, .gte => return Air.Inst.Ref.bool_true, | 32241 | .neq, .gt, .gte => return .bool_true, |
| 32062 | .eq, .lt, .lte => return Air.Inst.Ref.bool_false, | 32242 | .eq, .lt, .lte => return .bool_false, |
| 32063 | }, | 32243 | }, |
| 32064 | } | 32244 | } |
| 32065 | } | 32245 | } |
| 32066 | if (rhs_is_float) { | 32246 | if (rhs_is_float) { |
| 32067 | if (rhs_val.floatHasFraction(mod)) { | 32247 | if (rhs_val.floatHasFraction(mod)) { |
| 32068 | switch (op) { | 32248 | switch (op) { |
| 32069 | .eq => return Air.Inst.Ref.bool_false, | 32249 | .eq => return .bool_false, |
| 32070 | .neq => return Air.Inst.Ref.bool_true, | 32250 | .neq => return .bool_true, |
| 32071 | else => {}, | 32251 | else => {}, |
| 32072 | } | 32252 | } |
| 32073 | } | 32253 | } |
| ... | @@ -32185,7 +32365,7 @@ fn compareIntsOnlyPossibleResult( | ... | @@ -32185,7 +32365,7 @@ fn compareIntsOnlyPossibleResult( |
| 32185 | | 32365 | |
| 32186 | const ty = try mod.intType( | 32366 | const ty = try mod.intType( |
| 32187 | if (is_negative) .signed else .unsigned, | 32367 | if (is_negative) .signed else .unsigned, |
| 32188 | @as(u16, @intCast(req_bits)), | 32368 | @intCast(req_bits), |
| 32189 | ); | 32369 | ); |
| 32190 | const pop_count = lhs_val.popCount(ty, mod); | 32370 | const pop_count = lhs_val.popCount(ty, mod); |
| 32191 | | 32371 | |
| ... | @@ -32687,7 +32867,7 @@ fn resolvePeerTypes( | ... | @@ -32687,7 +32867,7 @@ fn resolvePeerTypes( |
| 32687 | .success => |ty| return ty, | 32867 | .success => |ty| return ty, |
| 32688 | else => |result| { | 32868 | else => |result| { |
| 32689 | const msg = try result.report(sema, block, src, instructions, candidate_srcs); | 32869 | const msg = try result.report(sema, block, src, instructions, candidate_srcs); |
| 32690 | return sema.failWithOwnedErrorMsg(msg); | 32870 | return sema.failWithOwnedErrorMsg(block, msg); |
| 32691 | }, | 32871 | }, |
| 32692 | } | 32872 | } |
| 32693 | } | 32873 | } |
| ... | @@ -32960,7 +33140,7 @@ fn resolvePeerTypesInner( | ... | @@ -32960,7 +33140,7 @@ fn resolvePeerTypesInner( |
| 32960 | }; | 33140 | }; |
| 32961 | | 33141 | |
| 32962 | return .{ .success = try mod.vectorType(.{ | 33142 | return .{ .success = try mod.vectorType(.{ |
| 32963 | .len = @as(u32, @intCast(len.?)), | 33143 | .len = @intCast(len.?), |
| 32964 | .child = child_ty.toIntern(), | 33144 | .child = child_ty.toIntern(), |
| 32965 | }) }; | 33145 | }) }; |
| 32966 | }, | 33146 | }, |
| ... | @@ -34045,7 +34225,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -34045,7 +34225,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 34045 | "struct '{}' depends on itself", | 34225 | "struct '{}' depends on itself", |
| 34046 | .{ty.fmt(mod)}, | 34226 | .{ty.fmt(mod)}, |
| 34047 | ); | 34227 | ); |
| 34048 | return sema.failWithOwnedErrorMsg(msg); | 34228 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34049 | }, | 34229 | }, |
| 34050 | .have_layout, .fully_resolved_wip, .fully_resolved => return, | 34230 | .have_layout, .fully_resolved_wip, .fully_resolved => return, |
| 34051 | } | 34231 | } |
| ... | @@ -34080,7 +34260,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -34080,7 +34260,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 34080 | "struct layout depends on it having runtime bits", | 34260 | "struct layout depends on it having runtime bits", |
| 34081 | .{}, | 34261 | .{}, |
| 34082 | ); | 34262 | ); |
| 34083 | return sema.failWithOwnedErrorMsg(msg); | 34263 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34084 | } | 34264 | } |
| 34085 | | 34265 | |
| 34086 | if (struct_obj.layout == .Auto and !struct_obj.is_tuple and | 34266 | if (struct_obj.layout == .Auto and !struct_obj.is_tuple and |
| ... | @@ -34090,7 +34270,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -34090,7 +34270,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 34090 | | 34270 | |
| 34091 | for (struct_obj.fields.values(), 0..) |field, i| { | 34271 | for (struct_obj.fields.values(), 0..) |field, i| { |
| 34092 | optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty)) | 34272 | optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty)) |
| 34093 | @as(u32, @intCast(i)) | 34273 | @intCast(i) |
| 34094 | else | 34274 | else |
| 34095 | Module.Struct.omitted_field; | 34275 | Module.Struct.omitted_field; |
| 34096 | } | 34276 | } |
| ... | @@ -34131,7 +34311,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -34131,7 +34311,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 34131 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; | 34311 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 34132 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 34312 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 34133 | assert(extended.opcode == .struct_decl); | 34313 | assert(extended.opcode == .struct_decl); |
| 34134 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 34314 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 34135 | | 34315 | |
| 34136 | if (small.has_backing_int) { | 34316 | if (small.has_backing_int) { |
| 34137 | var extra_index: usize = extended.operand; | 34317 | var extra_index: usize = extended.operand; |
| ... | @@ -34182,7 +34362,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -34182,7 +34362,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 34182 | const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 }; | 34362 | const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 }; |
| 34183 | const backing_int_ty = blk: { | 34363 | const backing_int_ty = blk: { |
| 34184 | if (backing_int_body_len == 0) { | 34364 | if (backing_int_body_len == 0) { |
| 34185 | const backing_int_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index])); | 34365 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 34186 | break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref); | 34366 | break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref); |
| 34187 | } else { | 34367 | } else { |
| 34188 | const body = zir.extra[extra_index..][0..backing_int_body_len]; | 34368 | const body = zir.extra[extra_index..][0..backing_int_body_len]; |
| ... | @@ -34228,7 +34408,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -34228,7 +34408,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 34228 | }; | 34408 | }; |
| 34229 | return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); | 34409 | return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); |
| 34230 | } | 34410 | } |
| 34231 | struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum))); | 34411 | struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); |
| 34232 | } | 34412 | } |
| 34233 | } | 34413 | } |
| 34234 | | 34414 | |
| ... | @@ -34257,7 +34437,7 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { | ... | @@ -34257,7 +34437,7 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 34257 | try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{}); | 34437 | try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{}); |
| 34258 | break :msg msg; | 34438 | break :msg msg; |
| 34259 | }; | 34439 | }; |
| 34260 | return sema.failWithOwnedErrorMsg(msg); | 34440 | return sema.failWithOwnedErrorMsg(block, msg); |
| 34261 | } | 34441 | } |
| 34262 | } | 34442 | } |
| 34263 | | 34443 | |
| ... | @@ -34280,7 +34460,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void | ... | @@ -34280,7 +34460,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void |
| 34280 | try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); | 34460 | try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); |
| 34281 | break :msg msg; | 34461 | break :msg msg; |
| 34282 | }; | 34462 | }; |
| 34283 | return sema.failWithOwnedErrorMsg(msg); | 34463 | return sema.failWithOwnedErrorMsg(block, msg); |
| 34284 | } | 34464 | } |
| 34285 | | 34465 | |
| 34286 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | 34466 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| ... | @@ -34297,7 +34477,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -34297,7 +34477,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 34297 | "union '{}' depends on itself", | 34477 | "union '{}' depends on itself", |
| 34298 | .{ty.fmt(mod)}, | 34478 | .{ty.fmt(mod)}, |
| 34299 | ); | 34479 | ); |
| 34300 | return sema.failWithOwnedErrorMsg(msg); | 34480 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34301 | }, | 34481 | }, |
| 34302 | .have_layout, .fully_resolved_wip, .fully_resolved => return, | 34482 | .have_layout, .fully_resolved_wip, .fully_resolved => return, |
| 34303 | } | 34483 | } |
| ... | @@ -34328,7 +34508,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -34328,7 +34508,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 34328 | "union layout depends on it having runtime bits", | 34508 | "union layout depends on it having runtime bits", |
| 34329 | .{}, | 34509 | .{}, |
| 34330 | ); | 34510 | ); |
| 34331 | return sema.failWithOwnedErrorMsg(msg); | 34511 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34332 | } | 34512 | } |
| 34333 | } | 34513 | } |
| 34334 | | 34514 | |
| ... | @@ -34586,7 +34766,7 @@ fn resolveTypeFieldsStruct( | ... | @@ -34586,7 +34766,7 @@ fn resolveTypeFieldsStruct( |
| 34586 | "struct '{}' depends on itself", | 34766 | "struct '{}' depends on itself", |
| 34587 | .{ty.fmt(sema.mod)}, | 34767 | .{ty.fmt(sema.mod)}, |
| 34588 | ); | 34768 | ); |
| 34589 | return sema.failWithOwnedErrorMsg(msg); | 34769 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34590 | }, | 34770 | }, |
| 34591 | .have_field_types, | 34771 | .have_field_types, |
| 34592 | .have_layout, | 34772 | .have_layout, |
| ... | @@ -34626,7 +34806,7 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Key.Unio | ... | @@ -34626,7 +34806,7 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Key.Unio |
| 34626 | "union '{}' depends on itself", | 34806 | "union '{}' depends on itself", |
| 34627 | .{ty.fmt(mod)}, | 34807 | .{ty.fmt(mod)}, |
| 34628 | ); | 34808 | ); |
| 34629 | return sema.failWithOwnedErrorMsg(msg); | 34809 | return sema.failWithOwnedErrorMsg(null, msg); |
| 34630 | }, | 34810 | }, |
| 34631 | .have_field_types, | 34811 | .have_field_types, |
| 34632 | .have_layout, | 34812 | .have_layout, |
| ... | @@ -34680,7 +34860,7 @@ fn resolveInferredErrorSet( | ... | @@ -34680,7 +34860,7 @@ fn resolveInferredErrorSet( |
| 34680 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{}); | 34860 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{}); |
| 34681 | break :msg msg; | 34861 | break :msg msg; |
| 34682 | }; | 34862 | }; |
| 34683 | return sema.failWithOwnedErrorMsg(msg); | 34863 | return sema.failWithOwnedErrorMsg(block, msg); |
| 34684 | } | 34864 | } |
| 34685 | // In this case we are dealing with the actual InferredErrorSet object that | 34865 | // In this case we are dealing with the actual InferredErrorSet object that |
| 34686 | // corresponds to the function, not one created to track an inline/comptime call. | 34866 | // corresponds to the function, not one created to track an inline/comptime call. |
| ... | @@ -34789,7 +34969,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -34789,7 +34969,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 34789 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; | 34969 | const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir; |
| 34790 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; | 34970 | const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended; |
| 34791 | assert(extended.opcode == .struct_decl); | 34971 | assert(extended.opcode == .struct_decl); |
| 34792 | const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small)); | 34972 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 34793 | var extra_index: usize = extended.operand; | 34973 | var extra_index: usize = extended.operand; |
| 34794 | | 34974 | |
| 34795 | const src = LazySrcLoc.nodeOffset(0); | 34975 | const src = LazySrcLoc.nodeOffset(0); |
| ... | @@ -34917,7 +35097,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -34917,7 +35097,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 34917 | if (has_type_body) { | 35097 | if (has_type_body) { |
| 34918 | fields[field_i].type_body_len = zir.extra[extra_index]; | 35098 | fields[field_i].type_body_len = zir.extra[extra_index]; |
| 34919 | } else { | 35099 | } else { |
| 34920 | fields[field_i].type_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index])); | 35100 | fields[field_i].type_ref = @enumFromInt(zir.extra[extra_index]); |
| 34921 | } | 35101 | } |
| 34922 | extra_index += 1; | 35102 | extra_index += 1; |
| 34923 | | 35103 | |
| ... | @@ -34940,7 +35120,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -34940,7 +35120,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 34940 | try sema.errNote(&block_scope, src, msg, "struct declared here", .{}); | 35120 | try sema.errNote(&block_scope, src, msg, "struct declared here", .{}); |
| 34941 | break :msg msg; | 35121 | break :msg msg; |
| 34942 | }; | 35122 | }; |
| 34943 | return sema.failWithOwnedErrorMsg(msg); | 35123 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 34944 | } | 35124 | } |
| 34945 | gop.value_ptr.* = .{ | 35125 | gop.value_ptr.* = .{ |
| 34946 | .ty = Type.noreturn, | 35126 | .ty = Type.noreturn, |
| ... | @@ -35016,7 +35196,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35016,7 +35196,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35016 | try sema.addDeclaredHereNote(msg, field_ty); | 35196 | try sema.addDeclaredHereNote(msg, field_ty); |
| 35017 | break :msg msg; | 35197 | break :msg msg; |
| 35018 | }; | 35198 | }; |
| 35019 | return sema.failWithOwnedErrorMsg(msg); | 35199 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35020 | } | 35200 | } |
| 35021 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 35201 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 35022 | const msg = msg: { | 35202 | const msg = msg: { |
| ... | @@ -35030,7 +35210,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35030,7 +35210,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35030 | try sema.addDeclaredHereNote(msg, field_ty); | 35210 | try sema.addDeclaredHereNote(msg, field_ty); |
| 35031 | break :msg msg; | 35211 | break :msg msg; |
| 35032 | }; | 35212 | }; |
| 35033 | return sema.failWithOwnedErrorMsg(msg); | 35213 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35034 | } | 35214 | } |
| 35035 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field.ty, .struct_field)) { | 35215 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field.ty, .struct_field)) { |
| 35036 | const msg = msg: { | 35216 | const msg = msg: { |
| ... | @@ -35046,7 +35226,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35046,7 +35226,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35046 | try sema.addDeclaredHereNote(msg, field.ty); | 35226 | try sema.addDeclaredHereNote(msg, field.ty); |
| 35047 | break :msg msg; | 35227 | break :msg msg; |
| 35048 | }; | 35228 | }; |
| 35049 | return sema.failWithOwnedErrorMsg(msg); | 35229 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35050 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty, mod))) { | 35230 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty, mod))) { |
| 35051 | const msg = msg: { | 35231 | const msg = msg: { |
| 35052 | const ty_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ | 35232 | const ty_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ |
| ... | @@ -35061,7 +35241,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35061,7 +35241,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35061 | try sema.addDeclaredHereNote(msg, field.ty); | 35241 | try sema.addDeclaredHereNote(msg, field.ty); |
| 35062 | break :msg msg; | 35242 | break :msg msg; |
| 35063 | }; | 35243 | }; |
| 35064 | return sema.failWithOwnedErrorMsg(msg); | 35244 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35065 | } | 35245 | } |
| 35066 | | 35246 | |
| 35067 | if (zir_field.align_body_len > 0) { | 35247 | if (zir_field.align_body_len > 0) { |
| ... | @@ -35112,7 +35292,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -35112,7 +35292,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 35112 | .index = field_i, | 35292 | .index = field_i, |
| 35113 | .range = .value, | 35293 | .range = .value, |
| 35114 | }).lazy; | 35294 | }).lazy; |
| 35115 | return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known"); | 35295 | return sema.failWithNeededComptime(&block_scope, init_src, .{ |
| | 35296 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| | 35297 | }); |
| 35116 | }; | 35298 | }; |
| 35117 | field.default_val = try default_val.intern(field.ty, mod); | 35299 | field.default_val = try default_val.intern(field.ty, mod); |
| 35118 | } | 35300 | } |
| ... | @@ -35247,7 +35429,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35247,7 +35429,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35247 | }); | 35429 | }); |
| 35248 | break :msg msg; | 35430 | break :msg msg; |
| 35249 | }; | 35431 | }; |
| 35250 | return sema.failWithOwnedErrorMsg(msg); | 35432 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35251 | } | 35433 | } |
| 35252 | enum_field_names = try sema.arena.alloc(InternPool.NullTerminatedString, fields_len); | 35434 | enum_field_names = try sema.arena.alloc(InternPool.NullTerminatedString, fields_len); |
| 35253 | try enum_field_vals.ensureTotalCapacity(sema.arena, fields_len); | 35435 | try enum_field_vals.ensureTotalCapacity(sema.arena, fields_len); |
| ... | @@ -35362,7 +35544,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35362,7 +35544,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35362 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); | 35544 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); |
| 35363 | break :msg msg; | 35545 | break :msg msg; |
| 35364 | }; | 35546 | }; |
| 35365 | return sema.failWithOwnedErrorMsg(msg); | 35547 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35366 | } | 35548 | } |
| 35367 | } | 35549 | } |
| 35368 | | 35550 | |
| ... | @@ -35407,7 +35589,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35407,7 +35589,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35407 | try sema.errNote(&block_scope, src, msg, "union declared here", .{}); | 35589 | try sema.errNote(&block_scope, src, msg, "union declared here", .{}); |
| 35408 | break :msg msg; | 35590 | break :msg msg; |
| 35409 | }; | 35591 | }; |
| 35410 | return sema.failWithOwnedErrorMsg(msg); | 35592 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35411 | } | 35593 | } |
| 35412 | | 35594 | |
| 35413 | if (explicit_tags_seen.len > 0) { | 35595 | if (explicit_tags_seen.len > 0) { |
| ... | @@ -35425,7 +35607,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35425,7 +35607,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35425 | try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType()); | 35607 | try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType()); |
| 35426 | break :msg msg; | 35608 | break :msg msg; |
| 35427 | }; | 35609 | }; |
| 35428 | return sema.failWithOwnedErrorMsg(msg); | 35610 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35429 | }; | 35611 | }; |
| 35430 | // No check for duplicate because the check already happened in order | 35612 | // No check for duplicate because the check already happened in order |
| 35431 | // to create the enum type in the first place. | 35613 | // to create the enum type in the first place. |
| ... | @@ -35447,7 +35629,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35447,7 +35629,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35447 | try sema.errNote(&block_scope, enum_field_src, msg, "enum field here", .{}); | 35629 | try sema.errNote(&block_scope, enum_field_src, msg, "enum field here", .{}); |
| 35448 | break :msg msg; | 35630 | break :msg msg; |
| 35449 | }; | 35631 | }; |
| 35450 | return sema.failWithOwnedErrorMsg(msg); | 35632 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35451 | } | 35633 | } |
| 35452 | } | 35634 | } |
| 35453 | | 35635 | |
| ... | @@ -35463,7 +35645,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35463,7 +35645,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35463 | try sema.addDeclaredHereNote(msg, field_ty); | 35645 | try sema.addDeclaredHereNote(msg, field_ty); |
| 35464 | break :msg msg; | 35646 | break :msg msg; |
| 35465 | }; | 35647 | }; |
| 35466 | return sema.failWithOwnedErrorMsg(msg); | 35648 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35467 | } | 35649 | } |
| 35468 | const layout = union_type.getLayout(ip); | 35650 | const layout = union_type.getLayout(ip); |
| 35469 | if (layout == .Extern and | 35651 | if (layout == .Extern and |
| ... | @@ -35482,7 +35664,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35482,7 +35664,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35482 | try sema.addDeclaredHereNote(msg, field_ty); | 35664 | try sema.addDeclaredHereNote(msg, field_ty); |
| 35483 | break :msg msg; | 35665 | break :msg msg; |
| 35484 | }; | 35666 | }; |
| 35485 | return sema.failWithOwnedErrorMsg(msg); | 35667 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35486 | } else if (layout == .Packed and !validatePackedType(field_ty, mod)) { | 35668 | } else if (layout == .Packed and !validatePackedType(field_ty, mod)) { |
| 35487 | const msg = msg: { | 35669 | const msg = msg: { |
| 35488 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 35670 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| ... | @@ -35497,7 +35679,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35497,7 +35679,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35497 | try sema.addDeclaredHereNote(msg, field_ty); | 35679 | try sema.addDeclaredHereNote(msg, field_ty); |
| 35498 | break :msg msg; | 35680 | break :msg msg; |
| 35499 | }; | 35681 | }; |
| 35500 | return sema.failWithOwnedErrorMsg(msg); | 35682 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35501 | } | 35683 | } |
| 35502 | | 35684 | |
| 35503 | field_types.appendAssumeCapacity(field_ty.toIntern()); | 35685 | field_types.appendAssumeCapacity(field_ty.toIntern()); |
| ... | @@ -35541,7 +35723,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35541,7 +35723,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35541 | try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType()); | 35723 | try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType()); |
| 35542 | break :msg msg; | 35724 | break :msg msg; |
| 35543 | }; | 35725 | }; |
| 35544 | return sema.failWithOwnedErrorMsg(msg); | 35726 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35545 | } | 35727 | } |
| 35546 | } else if (enum_field_vals.count() > 0) { | 35728 | } else if (enum_field_vals.count() > 0) { |
| 35547 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl)); | 35729 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl)); |
| ... | @@ -35554,7 +35736,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un | ... | @@ -35554,7 +35736,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 35554 | | 35736 | |
| 35555 | fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value { | 35737 | fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value { |
| 35556 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src); | 35738 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src); |
| 35557 | return sema.resolveConstValue(block, src, coerced, "enum tag value must be comptime-known"); | 35739 | return sema.resolveConstValue(block, src, coerced, .{ |
| | 35740 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| | 35741 | }); |
| 35558 | } | 35742 | } |
| 35559 | | 35743 | |
| 35560 | fn generateUnionTagTypeNumbered( | 35744 | fn generateUnionTagTypeNumbered( |
| ... | @@ -35950,7 +36134,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -35950,7 +36134,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 35950 | .{ty.fmt(mod)}, | 36134 | .{ty.fmt(mod)}, |
| 35951 | ); | 36135 | ); |
| 35952 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); | 36136 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| 35953 | return sema.failWithOwnedErrorMsg(msg); | 36137 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35954 | } | 36138 | } |
| 35955 | if (try sema.typeHasOnePossibleValue(field.ty)) |field_opv| { | 36139 | if (try sema.typeHasOnePossibleValue(field.ty)) |field_opv| { |
| 35956 | field_val.* = try field_opv.intern(field.ty, mod); | 36140 | field_val.* = try field_opv.intern(field.ty, mod); |
| ... | @@ -36004,7 +36188,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -36004,7 +36188,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36004 | .{ty.fmt(mod)}, | 36188 | .{ty.fmt(mod)}, |
| 36005 | ); | 36189 | ); |
| 36006 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); | 36190 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); |
| 36007 | return sema.failWithOwnedErrorMsg(msg); | 36191 | return sema.failWithOwnedErrorMsg(null, msg); |
| 36008 | } | 36192 | } |
| 36009 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse | 36193 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 36010 | return null; | 36194 | return null; |
| ... | @@ -36076,13 +36260,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { | ... | @@ -36076,13 +36260,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { |
| 36076 | | 36260 | |
| 36077 | pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { | 36261 | pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { |
| 36078 | const fields = std.meta.fields(@TypeOf(extra)); | 36262 | const fields = std.meta.fields(@TypeOf(extra)); |
| 36079 | const result = @as(u32, @intCast(sema.air_extra.items.len)); | 36263 | const result: u32 = @intCast(sema.air_extra.items.len); |
| 36080 | inline for (fields) |field| { | 36264 | inline for (fields) |field| { |
| 36081 | sema.air_extra.appendAssumeCapacity(switch (field.type) { | 36265 | sema.air_extra.appendAssumeCapacity(switch (field.type) { |
| 36082 | u32 => @field(extra, field.name), | 36266 | u32 => @field(extra, field.name), |
| 36083 | Air.Inst.Ref => @intFromEnum(@field(extra, field.name)), | 36267 | i32 => @bitCast(@field(extra, field.name)), |
| 36084 | i32 => @as(u32, @bitCast(@field(extra, field.name))), | 36268 | Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(extra, field.name)), |
| 36085 | InternPool.Index => @intFromEnum(@field(extra, field.name)), | | |
| 36086 | else => @compileError("bad field type: " ++ @typeName(field.type)), | 36269 | else => @compileError("bad field type: " ++ @typeName(field.type)), |
| 36087 | }); | 36270 | }); |
| 36088 | } | 36271 | } |
| ... | @@ -36090,8 +36273,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { | ... | @@ -36090,8 +36273,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { |
| 36090 | } | 36273 | } |
| 36091 | | 36274 | |
| 36092 | fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void { | 36275 | fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void { |
| 36093 | const coerced = @as([]const u32, @ptrCast(refs)); | 36276 | sema.air_extra.appendSliceAssumeCapacity(@ptrCast(refs)); |
| 36094 | sema.air_extra.appendSliceAssumeCapacity(coerced); | | |
| 36095 | } | 36277 | } |
| 36096 | | 36278 | |
| 36097 | fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { | 36279 | fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index { |
| ... | @@ -36180,7 +36362,9 @@ pub fn analyzeAddressSpace( | ... | @@ -36180,7 +36362,9 @@ pub fn analyzeAddressSpace( |
| 36180 | ctx: AddressSpaceContext, | 36362 | ctx: AddressSpaceContext, |
| 36181 | ) !std.builtin.AddressSpace { | 36363 | ) !std.builtin.AddressSpace { |
| 36182 | const mod = sema.mod; | 36364 | const mod = sema.mod; |
| 36183 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "address space must be comptime-known"); | 36365 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, .{ |
| | 36366 | .needed_comptime_reason = "address space must be comptime-known", |
| | 36367 | }); |
| 36184 | const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); | 36368 | const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val); |
| 36185 | const target = sema.mod.getTarget(); | 36369 | const target = sema.mod.getTarget(); |
| 36186 | const arch = target.cpu.arch; | 36370 | const arch = target.cpu.arch; |
| ... | @@ -36547,7 +36731,7 @@ fn structFieldAlignment(sema: *Sema, field: Module.Struct.Field, layout: std.bui | ... | @@ -36547,7 +36731,7 @@ fn structFieldAlignment(sema: *Sema, field: Module.Struct.Field, layout: std.bui |
| 36547 | const mod = sema.mod; | 36731 | const mod = sema.mod; |
| 36548 | if (field.abi_align.toByteUnitsOptional()) |a| { | 36732 | if (field.abi_align.toByteUnitsOptional()) |a| { |
| 36549 | assert(layout != .Packed); | 36733 | assert(layout != .Packed); |
| 36550 | return @as(u32, @intCast(a)); | 36734 | return @intCast(a); |
| 36551 | } | 36735 | } |
| 36552 | switch (layout) { | 36736 | switch (layout) { |
| 36553 | .Packed => return 0, | 36737 | .Packed => return 0, |
| ... | @@ -36612,7 +36796,7 @@ fn structFieldIndex( | ... | @@ -36612,7 +36796,7 @@ fn structFieldIndex( |
| 36612 | const struct_obj = mod.typeToStruct(struct_ty).?; | 36796 | const struct_obj = mod.typeToStruct(struct_ty).?; |
| 36613 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse | 36797 | const field_index_usize = struct_obj.fields.getIndex(field_name) orelse |
| 36614 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name); | 36798 | return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name); |
| 36615 | return @as(u32, @intCast(field_index_usize)); | 36799 | return @intCast(field_index_usize); |
| 36616 | } | 36800 | } |
| 36617 | } | 36801 | } |
| 36618 | | 36802 | |
| ... | @@ -36626,12 +36810,12 @@ fn anonStructFieldIndex( | ... | @@ -36626,12 +36810,12 @@ fn anonStructFieldIndex( |
| 36626 | const mod = sema.mod; | 36810 | const mod = sema.mod; |
| 36627 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { | 36811 | switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) { |
| 36628 | .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| { | 36812 | .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| { |
| 36629 | if (name == field_name) return @as(u32, @intCast(i)); | 36813 | if (name == field_name) return @intCast(i); |
| 36630 | }, | 36814 | }, |
| 36631 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| { | 36815 | .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| { |
| 36632 | for (struct_obj.fields.keys(), 0..) |name, i| { | 36816 | for (struct_obj.fields.keys(), 0..) |name, i| { |
| 36633 | if (name == field_name) { | 36817 | if (name == field_name) { |
| 36634 | return @as(u32, @intCast(i)); | 36818 | return @intCast(i); |
| 36635 | } | 36819 | } |
| 36636 | } | 36820 | } |
| 36637 | }, | 36821 | }, |
| ... | @@ -37229,9 +37413,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { | ... | @@ -37229,9 +37413,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { |
| 37229 | if (!is_packed) break :blk .{}; | 37413 | if (!is_packed) break :blk .{}; |
| 37230 | | 37414 | |
| 37231 | break :blk .{ | 37415 | break :blk .{ |
| 37232 | .host_size = @as(u16, @intCast(parent_ty.arrayLen(mod))), | 37416 | .host_size = @intCast(parent_ty.arrayLen(mod)), |
| 37233 | .alignment = @as(u32, @intCast(parent_ty.abiAlignment(mod))), | 37417 | .alignment = @intCast(parent_ty.abiAlignment(mod)), |
| 37234 | .vector_index = if (offset) |some| @as(VI, @enumFromInt(some)) else .runtime, | 37418 | .vector_index = if (offset) |some| @enumFromInt(some) else .runtime, |
| 37235 | }; | 37419 | }; |
| 37236 | } else .{}; | 37420 | } else .{}; |
| 37237 | | 37421 | |
| ... | @@ -37250,10 +37434,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { | ... | @@ -37250,10 +37434,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type { |
| 37250 | // The resulting pointer is aligned to the lcd between the offset (an | 37434 | // The resulting pointer is aligned to the lcd between the offset (an |
| 37251 | // arbitrary number) and the alignment factor (always a power of two, | 37435 | // arbitrary number) and the alignment factor (always a power of two, |
| 37252 | // non zero). | 37436 | // non zero). |
| 37253 | const new_align = @as(Alignment, @enumFromInt(@min( | 37437 | const new_align: Alignment = @enumFromInt(@min( |
| 37254 | @ctz(addend), | 37438 | @ctz(addend), |
| 37255 | @intFromEnum(ptr_info.flags.alignment), | 37439 | @intFromEnum(ptr_info.flags.alignment), |
| 37256 | ))); | 37440 | )); |
| 37257 | assert(new_align != .none); | 37441 | assert(new_align != .none); |
| 37258 | break :a new_align; | 37442 | break :a new_align; |
| 37259 | }; | 37443 | }; |