| ... | @@ -377,9 +377,7 @@ pub const Block = struct { | ... | @@ -377,9 +377,7 @@ pub const Block = struct { |
| 377 | runtime_index: RuntimeIndex = .zero, | 377 | runtime_index: RuntimeIndex = .zero, |
| 378 | inline_block: Zir.Inst.OptionalIndex = .none, | 378 | inline_block: Zir.Inst.OptionalIndex = .none, |
| 379 | | 379 | |
| 380 | comptime_reason: ?*const ComptimeReason = null, | 380 | comptime_reason: ?BlockComptimeReason = null, |
| 381 | // TODO is_comptime and comptime_reason should probably be merged together. | | |
| 382 | is_comptime: bool, | | |
| 383 | is_typeof: bool = false, | 381 | is_typeof: bool = false, |
| 384 | | 382 | |
| 385 | /// Keep track of the active error return trace index around blocks so that we can correctly | 383 | /// Keep track of the active error return trace index around blocks so that we can correctly |
| ... | @@ -419,6 +417,10 @@ pub const Block = struct { | ... | @@ -419,6 +417,10 @@ pub const Block = struct { |
| 419 | }; | 417 | }; |
| 420 | } | 418 | } |
| 421 | | 419 | |
| | 420 | fn isComptime(block: Block) bool { |
| | 421 | return block.comptime_reason != null; |
| | 422 | } |
| | 423 | |
| 422 | fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc { | 424 | fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc { |
| 423 | return block.src(.{ .node_offset_builtin_call_arg = .{ | 425 | return block.src(.{ .node_offset_builtin_call_arg = .{ |
| 424 | .builtin_call_node = builtin_call_node, | 426 | .builtin_call_node = builtin_call_node, |
| ... | @@ -434,44 +436,6 @@ pub const Block = struct { | ... | @@ -434,44 +436,6 @@ pub const Block = struct { |
| 434 | return block.src(.{ .token_offset = tok_offset }); | 436 | return block.src(.{ .token_offset = tok_offset }); |
| 435 | } | 437 | } |
| 436 | | 438 | |
| 437 | const ComptimeReason = union(enum) { | | |
| 438 | c_import: struct { | | |
| 439 | src: LazySrcLoc, | | |
| 440 | }, | | |
| 441 | comptime_ret_ty: struct { | | |
| 442 | func: Air.Inst.Ref, | | |
| 443 | func_src: LazySrcLoc, | | |
| 444 | return_ty: Type, | | |
| 445 | }, | | |
| 446 | | | |
| 447 | fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Zcu.ErrorMsg) !void { | | |
| 448 | const parent = msg orelse return; | | |
| 449 | const pt = sema.pt; | | |
| 450 | const prefix = "expression is evaluated at comptime because "; | | |
| 451 | switch (cr) { | | |
| 452 | .c_import => |ci| { | | |
| 453 | try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{}); | | |
| 454 | }, | | |
| 455 | .comptime_ret_ty => |rt| { | | |
| 456 | const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrcInst(rt.func)) |fn_decl_inst| .{ | | |
| 457 | .base_node_inst = fn_decl_inst, | | |
| 458 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, | | |
| 459 | } else rt.func_src; | | |
| 460 | if (rt.return_ty.isGenericPoison()) { | | |
| 461 | return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); | | |
| 462 | } | | |
| 463 | try sema.errNote( | | |
| 464 | ret_ty_src, | | |
| 465 | parent, | | |
| 466 | prefix ++ "the function returns a comptime-only type '{}'", | | |
| 467 | .{rt.return_ty.fmt(pt)}, | | |
| 468 | ); | | |
| 469 | try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty); | | |
| 470 | }, | | |
| 471 | } | | |
| 472 | } | | |
| 473 | }; | | |
| 474 | | | |
| 475 | const Param = struct { | 439 | const Param = struct { |
| 476 | /// `none` means `anytype`. | 440 | /// `none` means `anytype`. |
| 477 | ty: InternPool.Index, | 441 | ty: InternPool.Index, |
| ... | @@ -539,7 +503,6 @@ pub const Block = struct { | ... | @@ -539,7 +503,6 @@ pub const Block = struct { |
| 539 | .instructions = .{}, | 503 | .instructions = .{}, |
| 540 | .label = null, | 504 | .label = null, |
| 541 | .inlining = parent.inlining, | 505 | .inlining = parent.inlining, |
| 542 | .is_comptime = parent.is_comptime, | | |
| 543 | .comptime_reason = parent.comptime_reason, | 506 | .comptime_reason = parent.comptime_reason, |
| 544 | .is_typeof = parent.is_typeof, | 507 | .is_typeof = parent.is_typeof, |
| 545 | .runtime_cond = parent.runtime_cond, | 508 | .runtime_cond = parent.runtime_cond, |
| ... | @@ -860,6 +823,77 @@ pub const Block = struct { | ... | @@ -860,6 +823,77 @@ pub const Block = struct { |
| 860 | .inst = inst, | 823 | .inst = inst, |
| 861 | }); | 824 | }); |
| 862 | } | 825 | } |
| | 826 | |
| | 827 | /// Returns the `*Block` that should be passed to `Sema.failWithOwnedErrorMsg`, because all inline |
| | 828 | /// calls below it have already been reported with "called at comptime from here" notes. |
| | 829 | fn explainWhyBlockIsComptime(start_block: *Block, err_msg: *Zcu.ErrorMsg) !*Block { |
| | 830 | const sema = start_block.sema; |
| | 831 | var block = start_block; |
| | 832 | while (true) { |
| | 833 | switch (block.comptime_reason.?) { |
| | 834 | .inlining_parent => { |
| | 835 | const inlining = block.inlining.?; |
| | 836 | try sema.errNote(inlining.call_src, err_msg, "called at comptime from here", .{}); |
| | 837 | block = inlining.call_block; |
| | 838 | }, |
| | 839 | .reason => |r| { |
| | 840 | try r.r.explain(sema, r.src, err_msg); |
| | 841 | return block; |
| | 842 | }, |
| | 843 | } |
| | 844 | } |
| | 845 | } |
| | 846 | }; |
| | 847 | |
| | 848 | const ComptimeReason = union(enum) { |
| | 849 | /// Evaluating at comptime for a reason in the `std.zig.SimpleComptimeReason` enum. |
| | 850 | simple: std.zig.SimpleComptimeReason, |
| | 851 | |
| | 852 | /// Evaluating at comptime because of a comptime-only type. |
| | 853 | /// The format string looks like "foo '{}' bar", where "{}" is the comptime-only type. |
| | 854 | /// We will then explain why this type is comptime-only. |
| | 855 | comptime_only: struct { |
| | 856 | ty: Type, |
| | 857 | msg: enum { |
| | 858 | union_init, |
| | 859 | struct_init, |
| | 860 | tuple_init, |
| | 861 | param_ty_arg, |
| | 862 | ret_ty_call, |
| | 863 | ret_ty_generic_call, |
| | 864 | }, |
| | 865 | }, |
| | 866 | |
| | 867 | fn explain(reason: ComptimeReason, sema: *Sema, src: LazySrcLoc, err_msg: *Zcu.ErrorMsg) !void { |
| | 868 | switch (reason) { |
| | 869 | .simple => |simple| { |
| | 870 | try sema.errNote(src, err_msg, "{s}", .{simple.message()}); |
| | 871 | }, |
| | 872 | .comptime_only => |co| { |
| | 873 | const pre, const post = switch (co.msg) { |
| | 874 | .union_init => .{ "initializer of comptime-only union", "must be comptime-known" }, |
| | 875 | .struct_init => .{ "initializer of comptime-only struct", "must be comptime-known" }, |
| | 876 | .tuple_init => .{ "initializer of comptime-only tuple", "must be comptime-known" }, |
| | 877 | .param_ty_arg => .{ "argument to parameter with comptime-only type", "must be comptime-known" }, |
| | 878 | .ret_ty_call => .{ "function with comptime-only return type", "is evaluated at comptime" }, |
| | 879 | .ret_ty_generic_call => .{ "generic function instantiated with comptime-only return type", "is evaluated at comptime" }, |
| | 880 | }; |
| | 881 | try sema.errNote(src, err_msg, "{s} '{}' {s}", .{ pre, co.ty.fmt(sema.pt), post }); |
| | 882 | try sema.explainWhyTypeIsComptime(err_msg, src, co.ty); |
| | 883 | }, |
| | 884 | } |
| | 885 | } |
| | 886 | }; |
| | 887 | |
| | 888 | const BlockComptimeReason = union(enum) { |
| | 889 | /// This block inherits being comptime-only from the `inlining` call site. |
| | 890 | inlining_parent, |
| | 891 | |
| | 892 | /// This block is comptime for the given reason at the given source location. |
| | 893 | reason: struct { |
| | 894 | src: LazySrcLoc, |
| | 895 | r: ComptimeReason, |
| | 896 | }, |
| 863 | }; | 897 | }; |
| 864 | | 898 | |
| 865 | const LabeledBlock = struct { | 899 | const LabeledBlock = struct { |
| ... | @@ -885,12 +919,6 @@ const InferredAlloc = struct { | ... | @@ -885,12 +919,6 @@ const InferredAlloc = struct { |
| 885 | prongs: std.ArrayListUnmanaged(Air.Inst.Index) = .empty, | 919 | prongs: std.ArrayListUnmanaged(Air.Inst.Index) = .empty, |
| 886 | }; | 920 | }; |
| 887 | | 921 | |
| 888 | const NeededComptimeReason = struct { | | |
| 889 | needed_comptime_reason: []const u8, | | |
| 890 | value_comptime_reason: ?[]const u8 = null, | | |
| 891 | block_comptime_reason: ?*const Block.ComptimeReason = null, | | |
| 892 | }; | | |
| 893 | | | |
| 894 | pub fn deinit(sema: *Sema) void { | 922 | pub fn deinit(sema: *Sema) void { |
| 895 | const gpa = sema.gpa; | 923 | const gpa = sema.gpa; |
| 896 | sema.air_instructions.deinit(gpa); | 924 | sema.air_instructions.deinit(gpa); |
| ... | @@ -954,7 +982,7 @@ pub fn analyzeFnBody( | ... | @@ -954,7 +982,7 @@ pub fn analyzeFnBody( |
| 954 | /// we are evaluating at comptime, semantically analyze the body and return the result from it. | 982 | /// we are evaluating at comptime, semantically analyze the body and return the result from it. |
| 955 | /// Returns `null` if control flow did not break from this block, but instead terminated with some | 983 | /// Returns `null` if control flow did not break from this block, but instead terminated with some |
| 956 | /// other runtime noreturn instruction. Compile-time breaks to blocks further up the stack still | 984 | /// other runtime noreturn instruction. Compile-time breaks to blocks further up the stack still |
| 957 | /// return `error.ComptimeBreak`. If `block.is_comptime`, this function will never return `null`. | 985 | /// return `error.ComptimeBreak`. If `block.isComptime()`, this function will never return `null`. |
| 958 | fn analyzeInlineBody( | 986 | fn analyzeInlineBody( |
| 959 | sema: *Sema, | 987 | sema: *Sema, |
| 960 | block: *Block, | 988 | block: *Block, |
| ... | @@ -1003,7 +1031,7 @@ pub fn resolveInlineBody( | ... | @@ -1003,7 +1031,7 @@ pub fn resolveInlineBody( |
| 1003 | /// If this function returns normally, the merges of `block` were populated with all possible | 1031 | /// If this function returns normally, the merges of `block` were populated with all possible |
| 1004 | /// (runtime) results of this block. Peer type resolution should be performed on the result, | 1032 | /// (runtime) results of this block. Peer type resolution should be performed on the result, |
| 1005 | /// and relevant runtime instructions written to perform necessary coercions and breaks. See | 1033 | /// and relevant runtime instructions written to perform necessary coercions and breaks. See |
| 1006 | /// `resolveAnalyzedBlock`. This form of return is impossible if `block.is_comptime == true`. | 1034 | /// `resolveAnalyzedBlock`. This form of return is impossible if `block.isComptime()`. |
| 1007 | /// | 1035 | /// |
| 1008 | /// Alternatively, this function may return `error.ComptimeBreak`. This indicates that comptime | 1036 | /// Alternatively, this function may return `error.ComptimeBreak`. This indicates that comptime |
| 1009 | /// control flow is happening, and we are breaking at comptime from a block indicated by the | 1037 | /// control flow is happening, and we are breaking at comptime from a block indicated by the |
| ... | @@ -1340,7 +1368,7 @@ fn analyzeBodyInner( | ... | @@ -1340,7 +1368,7 @@ fn analyzeBodyInner( |
| 1340 | continue; | 1368 | continue; |
| 1341 | }, | 1369 | }, |
| 1342 | .breakpoint => { | 1370 | .breakpoint => { |
| 1343 | if (!block.is_comptime) { | 1371 | if (!block.isComptime()) { |
| 1344 | _ = try block.addNoOp(.breakpoint); | 1372 | _ = try block.addNoOp(.breakpoint); |
| 1345 | } | 1373 | } |
| 1346 | i += 1; | 1374 | i += 1; |
| ... | @@ -1515,7 +1543,7 @@ fn analyzeBodyInner( | ... | @@ -1515,7 +1543,7 @@ fn analyzeBodyInner( |
| 1515 | continue; | 1543 | continue; |
| 1516 | }, | 1544 | }, |
| 1517 | .check_comptime_control_flow => { | 1545 | .check_comptime_control_flow => { |
| 1518 | if (!block.is_comptime) { | 1546 | if (!block.isComptime()) { |
| 1519 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 1547 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 1520 | const src = block.nodeOffset(inst_data.src_node); | 1548 | const src = block.nodeOffset(inst_data.src_node); |
| 1521 | const inline_block = inst_data.operand.toIndex().?; | 1549 | const inline_block = inst_data.operand.toIndex().?; |
| ... | @@ -1562,7 +1590,7 @@ fn analyzeBodyInner( | ... | @@ -1562,7 +1590,7 @@ fn analyzeBodyInner( |
| 1562 | | 1590 | |
| 1563 | // Special case instructions to handle comptime control flow. | 1591 | // Special case instructions to handle comptime control flow. |
| 1564 | .@"break" => { | 1592 | .@"break" => { |
| 1565 | if (block.is_comptime) { | 1593 | if (block.isComptime()) { |
| 1566 | sema.comptime_break_inst = inst; | 1594 | sema.comptime_break_inst = inst; |
| 1567 | return error.ComptimeBreak; | 1595 | return error.ComptimeBreak; |
| 1568 | } else { | 1596 | } else { |
| ... | @@ -1575,7 +1603,7 @@ fn analyzeBodyInner( | ... | @@ -1575,7 +1603,7 @@ fn analyzeBodyInner( |
| 1575 | return error.ComptimeBreak; | 1603 | return error.ComptimeBreak; |
| 1576 | }, | 1604 | }, |
| 1577 | .repeat => { | 1605 | .repeat => { |
| 1578 | if (block.is_comptime) { | 1606 | if (block.isComptime()) { |
| 1579 | // Send comptime control flow back to the beginning of this block. | 1607 | // Send comptime control flow back to the beginning of this block. |
| 1580 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); | 1608 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); |
| 1581 | try sema.emitBackwardBranch(block, src); | 1609 | try sema.emitBackwardBranch(block, src); |
| ... | @@ -1597,7 +1625,7 @@ fn analyzeBodyInner( | ... | @@ -1597,7 +1625,7 @@ fn analyzeBodyInner( |
| 1597 | i = 0; | 1625 | i = 0; |
| 1598 | continue; | 1626 | continue; |
| 1599 | }, | 1627 | }, |
| 1600 | .switch_continue => if (block.is_comptime) { | 1628 | .switch_continue => if (block.isComptime()) { |
| 1601 | sema.comptime_break_inst = inst; | 1629 | sema.comptime_break_inst = inst; |
| 1602 | return error.ComptimeBreak; | 1630 | return error.ComptimeBreak; |
| 1603 | } else { | 1631 | } else { |
| ... | @@ -1605,17 +1633,40 @@ fn analyzeBodyInner( | ... | @@ -1605,17 +1633,40 @@ fn analyzeBodyInner( |
| 1605 | break; | 1633 | break; |
| 1606 | }, | 1634 | }, |
| 1607 | | 1635 | |
| 1608 | .loop => if (block.is_comptime) { | 1636 | .loop => if (block.isComptime()) { |
| 1609 | continue :inst .block_inline; | 1637 | continue :inst .block_inline; |
| 1610 | } else try sema.zirLoop(block, inst), | 1638 | } else try sema.zirLoop(block, inst), |
| 1611 | | 1639 | |
| 1612 | .block => if (block.is_comptime) { | 1640 | .block => if (block.isComptime()) { |
| 1613 | continue :inst .block_inline; | 1641 | continue :inst .block_inline; |
| 1614 | } else try sema.zirBlock(block, inst, false), | 1642 | } else try sema.zirBlock(block, inst), |
| 1615 | | 1643 | |
| 1616 | .block_comptime => if (block.is_comptime) { | 1644 | .block_comptime => { |
| 1617 | continue :inst .block_inline; | 1645 | const pl_node = datas[@intFromEnum(inst)].pl_node; |
| 1618 | } else try sema.zirBlock(block, inst, true), | 1646 | const src = block.nodeOffset(pl_node.src_node); |
| | 1647 | const extra = sema.code.extraData(Zir.Inst.BlockComptime, pl_node.payload_index); |
| | 1648 | const block_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| | 1649 | |
| | 1650 | if (block.isComptime()) { |
| | 1651 | // No need for a sub-block; just resolve the other body directly! |
| | 1652 | break :inst try sema.resolveInlineBody(block, block_body, inst); |
| | 1653 | } |
| | 1654 | |
| | 1655 | var child_block = block.makeSubBlock(); |
| | 1656 | defer child_block.instructions.deinit(sema.gpa); |
| | 1657 | child_block.comptime_reason = .{ .reason = .{ |
| | 1658 | .src = src, |
| | 1659 | .r = .{ .simple = extra.data.reason }, |
| | 1660 | } }; |
| | 1661 | |
| | 1662 | const result = try sema.resolveInlineBody(&child_block, block_body, inst); |
| | 1663 | |
| | 1664 | if (!try sema.isComptimeKnown(result)) { |
| | 1665 | return sema.failWithNeededComptime(&child_block, src, null); |
| | 1666 | } |
| | 1667 | |
| | 1668 | break :inst result; |
| | 1669 | }, |
| 1619 | | 1670 | |
| 1620 | .block_inline => blk: { | 1671 | .block_inline => blk: { |
| 1621 | // Directly analyze the block body without introducing a new block. | 1672 | // Directly analyze the block body without introducing a new block. |
| ... | @@ -1725,7 +1776,7 @@ fn analyzeBodyInner( | ... | @@ -1725,7 +1776,7 @@ fn analyzeBodyInner( |
| 1725 | return error.ComptimeBreak; | 1776 | return error.ComptimeBreak; |
| 1726 | } | 1777 | } |
| 1727 | }, | 1778 | }, |
| 1728 | .condbr => if (block.is_comptime) { | 1779 | .condbr => if (block.isComptime()) { |
| 1729 | continue :inst .condbr_inline; | 1780 | continue :inst .condbr_inline; |
| 1730 | } else { | 1781 | } else { |
| 1731 | try sema.zirCondbr(block, inst); | 1782 | try sema.zirCondbr(block, inst); |
| ... | @@ -1742,10 +1793,7 @@ fn analyzeBodyInner( | ... | @@ -1742,10 +1793,7 @@ fn analyzeBodyInner( |
| 1742 | ); | 1793 | ); |
| 1743 | const uncasted_cond = try sema.resolveInst(extra.data.condition); | 1794 | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 1744 | const cond = try sema.coerce(block, Type.bool, uncasted_cond, cond_src); | 1795 | const cond = try sema.coerce(block, Type.bool, uncasted_cond, cond_src); |
| 1745 | const cond_val = try sema.resolveConstDefinedValue(block, cond_src, cond, .{ | 1796 | const cond_val = try sema.resolveConstDefinedValue(block, cond_src, cond, null); |
| 1746 | .needed_comptime_reason = "condition in comptime branch must be comptime-known", | | |
| 1747 | .block_comptime_reason = block.comptime_reason, | | |
| 1748 | }); | | |
| 1749 | const inline_body = if (cond_val.toBool()) then_body else else_body; | 1797 | const inline_body = if (cond_val.toBool()) then_body else else_body; |
| 1750 | | 1798 | |
| 1751 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); | 1799 | try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src); |
| ... | @@ -1756,7 +1804,7 @@ fn analyzeBodyInner( | ... | @@ -1756,7 +1804,7 @@ fn analyzeBodyInner( |
| 1756 | break :inst result; | 1804 | break :inst result; |
| 1757 | }, | 1805 | }, |
| 1758 | .@"try" => blk: { | 1806 | .@"try" => blk: { |
| 1759 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 1807 | if (!block.isComptime()) break :blk try sema.zirTry(block, inst); |
| 1760 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1808 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1761 | const src = block.nodeOffset(inst_data.src_node); | 1809 | const src = block.nodeOffset(inst_data.src_node); |
| 1762 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); | 1810 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| ... | @@ -1771,10 +1819,7 @@ fn analyzeBodyInner( | ... | @@ -1771,10 +1819,7 @@ fn analyzeBodyInner( |
| 1771 | } | 1819 | } |
| 1772 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1820 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1773 | assert(is_non_err != .none); | 1821 | assert(is_non_err != .none); |
| 1774 | const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, .{ | 1822 | const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, null); |
| 1775 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", | | |
| 1776 | .block_comptime_reason = block.comptime_reason, | | |
| 1777 | }); | | |
| 1778 | if (is_non_err_val.toBool()) { | 1823 | if (is_non_err_val.toBool()) { |
| 1779 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); | 1824 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); |
| 1780 | } | 1825 | } |
| ... | @@ -1782,7 +1827,7 @@ fn analyzeBodyInner( | ... | @@ -1782,7 +1827,7 @@ fn analyzeBodyInner( |
| 1782 | break :blk result; | 1827 | break :blk result; |
| 1783 | }, | 1828 | }, |
| 1784 | .try_ptr => blk: { | 1829 | .try_ptr => blk: { |
| 1785 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); | 1830 | if (!block.isComptime()) break :blk try sema.zirTryPtr(block, inst); |
| 1786 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1831 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1787 | const src = block.nodeOffset(inst_data.src_node); | 1832 | const src = block.nodeOffset(inst_data.src_node); |
| 1788 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); | 1833 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| ... | @@ -1792,10 +1837,7 @@ fn analyzeBodyInner( | ... | @@ -1792,10 +1837,7 @@ fn analyzeBodyInner( |
| 1792 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); | 1837 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1793 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1838 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1794 | assert(is_non_err != .none); | 1839 | assert(is_non_err != .none); |
| 1795 | const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, .{ | 1840 | const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, null); |
| 1796 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", | | |
| 1797 | .block_comptime_reason = block.comptime_reason, | | |
| 1798 | }); | | |
| 1799 | if (is_non_err_val.toBool()) { | 1841 | if (is_non_err_val.toBool()) { |
| 1800 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 1842 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 1801 | } | 1843 | } |
| ... | @@ -1873,7 +1915,7 @@ fn resolveConstBool( | ... | @@ -1873,7 +1915,7 @@ fn resolveConstBool( |
| 1873 | block: *Block, | 1915 | block: *Block, |
| 1874 | src: LazySrcLoc, | 1916 | src: LazySrcLoc, |
| 1875 | zir_ref: Zir.Inst.Ref, | 1917 | zir_ref: Zir.Inst.Ref, |
| 1876 | reason: NeededComptimeReason, | 1918 | reason: ComptimeReason, |
| 1877 | ) !bool { | 1919 | ) !bool { |
| 1878 | const air_inst = try sema.resolveInst(zir_ref); | 1920 | const air_inst = try sema.resolveInst(zir_ref); |
| 1879 | const wanted_type = Type.bool; | 1921 | const wanted_type = Type.bool; |
| ... | @@ -1887,7 +1929,7 @@ fn resolveConstString( | ... | @@ -1887,7 +1929,7 @@ fn resolveConstString( |
| 1887 | block: *Block, | 1929 | block: *Block, |
| 1888 | src: LazySrcLoc, | 1930 | src: LazySrcLoc, |
| 1889 | zir_ref: Zir.Inst.Ref, | 1931 | zir_ref: Zir.Inst.Ref, |
| 1890 | reason: NeededComptimeReason, | 1932 | reason: ComptimeReason, |
| 1891 | ) ![]u8 { | 1933 | ) ![]u8 { |
| 1892 | const air_inst = try sema.resolveInst(zir_ref); | 1934 | const air_inst = try sema.resolveInst(zir_ref); |
| 1893 | return sema.toConstString(block, src, air_inst, reason); | 1935 | return sema.toConstString(block, src, air_inst, reason); |
| ... | @@ -1898,7 +1940,7 @@ pub fn toConstString( | ... | @@ -1898,7 +1940,7 @@ pub fn toConstString( |
| 1898 | block: *Block, | 1940 | block: *Block, |
| 1899 | src: LazySrcLoc, | 1941 | src: LazySrcLoc, |
| 1900 | air_inst: Air.Inst.Ref, | 1942 | air_inst: Air.Inst.Ref, |
| 1901 | reason: NeededComptimeReason, | 1943 | reason: ComptimeReason, |
| 1902 | ) ![]u8 { | 1944 | ) ![]u8 { |
| 1903 | const pt = sema.pt; | 1945 | const pt = sema.pt; |
| 1904 | const coerced_inst = try sema.coerce(block, Type.slice_const_u8, air_inst, src); | 1946 | const coerced_inst = try sema.coerce(block, Type.slice_const_u8, air_inst, src); |
| ... | @@ -1912,7 +1954,7 @@ pub fn resolveConstStringIntern( | ... | @@ -1912,7 +1954,7 @@ pub fn resolveConstStringIntern( |
| 1912 | block: *Block, | 1954 | block: *Block, |
| 1913 | src: LazySrcLoc, | 1955 | src: LazySrcLoc, |
| 1914 | zir_ref: Zir.Inst.Ref, | 1956 | zir_ref: Zir.Inst.Ref, |
| 1915 | reason: NeededComptimeReason, | 1957 | reason: ComptimeReason, |
| 1916 | ) !InternPool.NullTerminatedString { | 1958 | ) !InternPool.NullTerminatedString { |
| 1917 | const air_inst = try sema.resolveInst(zir_ref); | 1959 | const air_inst = try sema.resolveInst(zir_ref); |
| 1918 | const wanted_type = Type.slice_const_u8; | 1960 | const wanted_type = Type.slice_const_u8; |
| ... | @@ -2063,9 +2105,7 @@ fn analyzeAsType( | ... | @@ -2063,9 +2105,7 @@ fn analyzeAsType( |
| 2063 | ) !Type { | 2105 | ) !Type { |
| 2064 | const wanted_type = Type.type; | 2106 | const wanted_type = Type.type; |
| 2065 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 2107 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 2066 | const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{ | 2108 | const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{ .simple = .type }); |
| 2067 | .needed_comptime_reason = "types must be comptime-known", | | |
| 2068 | }); | | |
| 2069 | return val.toType(); | 2109 | return val.toType(); |
| 2070 | } | 2110 | } |
| 2071 | | 2111 | |
| ... | @@ -2077,7 +2117,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2077,7 +2117,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2077 | const ip = &zcu.intern_pool; | 2117 | const ip = &zcu.intern_pool; |
| 2078 | if (!comp.config.any_error_tracing) return; | 2118 | if (!comp.config.any_error_tracing) return; |
| 2079 | | 2119 | |
| 2080 | assert(!block.is_comptime); | 2120 | assert(!block.isComptime()); |
| 2081 | var err_trace_block = block.makeSubBlock(); | 2121 | var err_trace_block = block.makeSubBlock(); |
| 2082 | defer err_trace_block.instructions.deinit(gpa); | 2122 | defer err_trace_block.instructions.deinit(gpa); |
| 2083 | | 2123 | |
| ... | @@ -2148,7 +2188,7 @@ fn resolveConstValue( | ... | @@ -2148,7 +2188,7 @@ fn resolveConstValue( |
| 2148 | block: *Block, | 2188 | block: *Block, |
| 2149 | src: LazySrcLoc, | 2189 | src: LazySrcLoc, |
| 2150 | inst: Air.Inst.Ref, | 2190 | inst: Air.Inst.Ref, |
| 2151 | reason: NeededComptimeReason, | 2191 | reason: ?ComptimeReason, |
| 2152 | ) CompileError!Value { | 2192 | ) CompileError!Value { |
| 2153 | return try sema.resolveValue(inst) orelse { | 2193 | return try sema.resolveValue(inst) orelse { |
| 2154 | return sema.failWithNeededComptime(block, src, reason); | 2194 | return sema.failWithNeededComptime(block, src, reason); |
| ... | @@ -2177,7 +2217,7 @@ fn resolveConstDefinedValue( | ... | @@ -2177,7 +2217,7 @@ fn resolveConstDefinedValue( |
| 2177 | block: *Block, | 2217 | block: *Block, |
| 2178 | src: LazySrcLoc, | 2218 | src: LazySrcLoc, |
| 2179 | air_ref: Air.Inst.Ref, | 2219 | air_ref: Air.Inst.Ref, |
| 2180 | reason: NeededComptimeReason, | 2220 | reason: ?ComptimeReason, |
| 2181 | ) CompileError!Value { | 2221 | ) CompileError!Value { |
| 2182 | const val = try sema.resolveConstValue(block, src, air_ref, reason); | 2222 | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| 2183 | if (val.isUndef(sema.pt.zcu)) return sema.failWithUseOfUndef(block, src); | 2223 | if (val.isUndef(sema.pt.zcu)) return sema.failWithUseOfUndef(block, src); |
| ... | @@ -2217,15 +2257,16 @@ pub fn resolveFinalDeclValue( | ... | @@ -2217,15 +2257,16 @@ pub fn resolveFinalDeclValue( |
| 2217 | const val: Value = .fromInterned(ip_index); | 2257 | const val: Value = .fromInterned(ip_index); |
| 2218 | break :rt_ptr val.isPtrRuntimeValue(zcu); | 2258 | break :rt_ptr val.isPtrRuntimeValue(zcu); |
| 2219 | }; | 2259 | }; |
| 2220 | const value_comptime_reason: ?[]const u8 = if (is_runtime_ptr) | | |
| 2221 | "thread local and dll imported variables have runtime-known addresses" | | |
| 2222 | else | | |
| 2223 | null; | | |
| 2224 | | 2260 | |
| 2225 | return sema.failWithNeededComptime(block, src, .{ | 2261 | switch (sema.failWithNeededComptime(block, src, .{ .simple = .container_var_init })) { |
| 2226 | .needed_comptime_reason = "global variable initializer must be comptime-known", | 2262 | error.AnalysisFail => |e| { |
| 2227 | .value_comptime_reason = value_comptime_reason, | 2263 | if (sema.err != null and is_runtime_ptr) { |
| 2228 | }); | 2264 | try sema.errNote(src, sema.err.?, "threadlocal and dll imported variables have runtime-known addresses", .{}); |
| | 2265 | } |
| | 2266 | return e; |
| | 2267 | }, |
| | 2268 | else => |e| return e, |
| | 2269 | } |
| 2229 | }; | 2270 | }; |
| 2230 | | 2271 | |
| 2231 | if (val.canMutateComptimeVarState(zcu)) { | 2272 | if (val.canMutateComptimeVarState(zcu)) { |
| ... | @@ -2235,21 +2276,19 @@ pub fn resolveFinalDeclValue( | ... | @@ -2235,21 +2276,19 @@ pub fn resolveFinalDeclValue( |
| 2235 | return val; | 2276 | return val; |
| 2236 | } | 2277 | } |
| 2237 | | 2278 | |
| 2238 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { | 2279 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: ?ComptimeReason) CompileError { |
| 2239 | const msg = msg: { | 2280 | const msg, const fail_block = msg: { |
| 2240 | const msg = try sema.errMsg(src, "unable to resolve comptime value", .{}); | 2281 | const msg = try sema.errMsg(src, "unable to resolve comptime value", .{}); |
| 2241 | errdefer msg.destroy(sema.gpa); | 2282 | errdefer msg.destroy(sema.gpa); |
| 2242 | try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason}); | 2283 | const fail_block = if (reason) |r| b: { |
| 2243 | if (reason.value_comptime_reason) |value_comptime_reason| { | 2284 | try r.explain(sema, src, msg); |
| 2244 | try sema.errNote(src, msg, "{s}", .{value_comptime_reason}); | 2285 | break :b block; |
| 2245 | } | 2286 | } else b: { |
| 2246 | | 2287 | break :b try block.explainWhyBlockIsComptime(msg); |
| 2247 | if (reason.block_comptime_reason) |block_comptime_reason| { | 2288 | }; |
| 2248 | try block_comptime_reason.explain(sema, msg); | 2289 | break :msg .{ msg, fail_block }; |
| 2249 | } | | |
| 2250 | break :msg msg; | | |
| 2251 | }; | 2290 | }; |
| 2252 | return sema.failWithOwnedErrorMsg(block, msg); | 2291 | return sema.failWithOwnedErrorMsg(fail_block, msg); |
| 2253 | } | 2292 | } |
| 2254 | | 2293 | |
| 2255 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 2294 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| ... | @@ -2578,9 +2617,7 @@ pub fn analyzeAsAlign( | ... | @@ -2578,9 +2617,7 @@ pub fn analyzeAsAlign( |
| 2578 | src: LazySrcLoc, | 2617 | src: LazySrcLoc, |
| 2579 | air_ref: Air.Inst.Ref, | 2618 | air_ref: Air.Inst.Ref, |
| 2580 | ) !Alignment { | 2619 | ) !Alignment { |
| 2581 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{ | 2620 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{ .simple = .@"align" }); |
| 2582 | .needed_comptime_reason = "alignment must be comptime-known", | | |
| 2583 | }); | | |
| 2584 | return sema.validateAlign(block, src, alignment_big); | 2621 | return sema.validateAlign(block, src, alignment_big); |
| 2585 | } | 2622 | } |
| 2586 | | 2623 | |
| ... | @@ -2615,7 +2652,7 @@ fn resolveInt( | ... | @@ -2615,7 +2652,7 @@ fn resolveInt( |
| 2615 | src: LazySrcLoc, | 2652 | src: LazySrcLoc, |
| 2616 | zir_ref: Zir.Inst.Ref, | 2653 | zir_ref: Zir.Inst.Ref, |
| 2617 | dest_ty: Type, | 2654 | dest_ty: Type, |
| 2618 | reason: NeededComptimeReason, | 2655 | reason: ComptimeReason, |
| 2619 | ) !u64 { | 2656 | ) !u64 { |
| 2620 | const air_ref = try sema.resolveInst(zir_ref); | 2657 | const air_ref = try sema.resolveInst(zir_ref); |
| 2621 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); | 2658 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); |
| ... | @@ -2627,7 +2664,7 @@ fn analyzeAsInt( | ... | @@ -2627,7 +2664,7 @@ fn analyzeAsInt( |
| 2627 | src: LazySrcLoc, | 2664 | src: LazySrcLoc, |
| 2628 | air_ref: Air.Inst.Ref, | 2665 | air_ref: Air.Inst.Ref, |
| 2629 | dest_ty: Type, | 2666 | dest_ty: Type, |
| 2630 | reason: NeededComptimeReason, | 2667 | reason: ComptimeReason, |
| 2631 | ) !u64 { | 2668 | ) !u64 { |
| 2632 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); | 2669 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| 2633 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); | 2670 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| ... | @@ -2687,9 +2724,7 @@ fn zirTupleDecl( | ... | @@ -2687,9 +2724,7 @@ fn zirTupleDecl( |
| 2687 | if (zir_field_init != .none) { | 2724 | if (zir_field_init != .none) { |
| 2688 | const uncoerced_field_init = try sema.resolveInst(zir_field_init); | 2725 | const uncoerced_field_init = try sema.resolveInst(zir_field_init); |
| 2689 | const coerced_field_init = try sema.coerce(block, field_type, uncoerced_field_init, init_src); | 2726 | const coerced_field_init = try sema.coerce(block, field_type, uncoerced_field_init, init_src); |
| 2690 | const field_init_val = try sema.resolveConstDefinedValue(block, init_src, coerced_field_init, .{ | 2727 | const field_init_val = try sema.resolveConstDefinedValue(block, init_src, coerced_field_init, .{ .simple = .tuple_field_default_value }); |
| 2691 | .needed_comptime_reason = "tuple field default value must be comptime-known", | | |
| 2692 | }); | | |
| 2693 | if (field_init_val.canMutateComptimeVarState(zcu)) { | 2728 | if (field_init_val.canMutateComptimeVarState(zcu)) { |
| 2694 | return sema.fail(block, init_src, "field default value contains reference to comptime-mutable memory", .{}); | 2729 | return sema.fail(block, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| 2695 | } | 2730 | } |
| ... | @@ -3414,7 +3449,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { | ... | @@ -3414,7 +3449,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref { |
| 3414 | | 3449 | |
| 3415 | const pt = sema.pt; | 3450 | const pt = sema.pt; |
| 3416 | | 3451 | |
| 3417 | if (block.is_comptime or try sema.fn_ret_ty.comptimeOnlySema(pt)) { | 3452 | if (block.isComptime() or try sema.fn_ret_ty.comptimeOnlySema(pt)) { |
| 3418 | try sema.fn_ret_ty.resolveFields(pt); | 3453 | try sema.fn_ret_ty.resolveFields(pt); |
| 3419 | return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty, .none); | 3454 | return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty, .none); |
| 3420 | } | 3455 | } |
| ... | @@ -3608,7 +3643,7 @@ fn zirAllocExtended( | ... | @@ -3608,7 +3643,7 @@ fn zirAllocExtended( |
| 3608 | break :blk try sema.resolveAlign(block, align_src, align_ref); | 3643 | break :blk try sema.resolveAlign(block, align_src, align_ref); |
| 3609 | } else .none; | 3644 | } else .none; |
| 3610 | | 3645 | |
| 3611 | if (block.is_comptime or small.is_comptime) { | 3646 | if (block.isComptime() or small.is_comptime) { |
| 3612 | if (small.has_type) { | 3647 | if (small.has_type) { |
| 3613 | return sema.analyzeComptimeAlloc(block, var_ty, alignment); | 3648 | return sema.analyzeComptimeAlloc(block, var_ty, alignment); |
| 3614 | } else { | 3649 | } else { |
| ... | @@ -4075,7 +4110,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -4075,7 +4110,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 4075 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); | 4110 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4076 | | 4111 | |
| 4077 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4112 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4078 | if (block.is_comptime or try var_ty.comptimeOnlySema(pt)) { | 4113 | if (block.isComptime() or try var_ty.comptimeOnlySema(pt)) { |
| 4079 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4114 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| 4080 | } | 4115 | } |
| 4081 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { | 4116 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { |
| ... | @@ -4103,7 +4138,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -4103,7 +4138,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 4103 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4138 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4104 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); | 4139 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4105 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4140 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4106 | if (block.is_comptime) { | 4141 | if (block.isComptime()) { |
| 4107 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4142 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| 4108 | } | 4143 | } |
| 4109 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { | 4144 | if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) { |
| ... | @@ -4129,7 +4164,7 @@ fn zirAllocInferred( | ... | @@ -4129,7 +4164,7 @@ fn zirAllocInferred( |
| 4129 | | 4164 | |
| 4130 | const gpa = sema.gpa; | 4165 | const gpa = sema.gpa; |
| 4131 | | 4166 | |
| 4132 | if (block.is_comptime) { | 4167 | if (block.isComptime()) { |
| 4133 | try sema.air_instructions.append(gpa, .{ | 4168 | try sema.air_instructions.append(gpa, .{ |
| 4134 | .tag = .inferred_alloc_comptime, | 4169 | .tag = .inferred_alloc_comptime, |
| 4135 | .data = .{ .inferred_alloc_comptime = .{ | 4170 | .data = .{ .inferred_alloc_comptime = .{ |
| ... | @@ -4778,7 +4813,7 @@ fn validateUnionInit( | ... | @@ -4778,7 +4813,7 @@ fn validateUnionInit( |
| 4778 | return sema.failWithOwnedErrorMsg(block, msg); | 4813 | return sema.failWithOwnedErrorMsg(block, msg); |
| 4779 | } | 4814 | } |
| 4780 | | 4815 | |
| 4781 | if (block.is_comptime and | 4816 | if (block.isComptime() and |
| 4782 | (try sema.resolveDefinedValue(block, init_src, union_ptr)) != null) | 4817 | (try sema.resolveDefinedValue(block, init_src, union_ptr)) != null) |
| 4783 | { | 4818 | { |
| 4784 | // In this case, comptime machinery already did everything. No work to do here. | 4819 | // In this case, comptime machinery already did everything. No work to do here. |
| ... | @@ -4897,9 +4932,11 @@ fn validateUnionInit( | ... | @@ -4897,9 +4932,11 @@ fn validateUnionInit( |
| 4897 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4932 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4898 | return; | 4933 | return; |
| 4899 | } else if (try union_ty.comptimeOnlySema(pt)) { | 4934 | } else if (try union_ty.comptimeOnlySema(pt)) { |
| 4900 | return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{ | 4935 | const src = block.nodeOffset(field_ptr_data.src_node); |
| 4901 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", | 4936 | return sema.failWithNeededComptime(block, src, .{ .comptime_only = .{ |
| 4902 | }); | 4937 | .ty = union_ty, |
| | 4938 | .msg = .union_init, |
| | 4939 | } }); |
| 4903 | } | 4940 | } |
| 4904 | if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v); | 4941 | if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v); |
| 4905 | | 4942 | |
| ... | @@ -4953,7 +4990,7 @@ fn validateStructInit( | ... | @@ -4953,7 +4990,7 @@ fn validateStructInit( |
| 4953 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); | 4990 | errdefer if (root_msg) |msg| msg.destroy(sema.gpa); |
| 4954 | | 4991 | |
| 4955 | const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref); | 4992 | const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref); |
| 4956 | if (block.is_comptime and | 4993 | if (block.isComptime() and |
| 4957 | (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null) | 4994 | (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null) |
| 4958 | { | 4995 | { |
| 4959 | try struct_ty.resolveLayout(pt); | 4996 | try struct_ty.resolveLayout(pt); |
| ... | @@ -5081,9 +5118,11 @@ fn validateStructInit( | ... | @@ -5081,9 +5118,11 @@ fn validateStructInit( |
| 5081 | field_values[i] = val.toIntern(); | 5118 | field_values[i] = val.toIntern(); |
| 5082 | } else if (require_comptime) { | 5119 | } else if (require_comptime) { |
| 5083 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 5120 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 5084 | return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{ | 5121 | const src = block.nodeOffset(field_ptr_data.src_node); |
| 5085 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 5122 | return sema.failWithNeededComptime(block, src, .{ .comptime_only = .{ |
| 5086 | }); | 5123 | .ty = struct_ty, |
| | 5124 | .msg = .struct_init, |
| | 5125 | } }); |
| 5087 | } else { | 5126 | } else { |
| 5088 | struct_is_comptime = false; | 5127 | struct_is_comptime = false; |
| 5089 | } | 5128 | } |
| ... | @@ -5253,7 +5292,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5253,7 +5292,7 @@ fn zirValidatePtrArrayInit( |
| 5253 | else => unreachable, | 5292 | else => unreachable, |
| 5254 | }; | 5293 | }; |
| 5255 | | 5294 | |
| 5256 | if (block.is_comptime and | 5295 | if (block.isComptime() and |
| 5257 | (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null) | 5296 | (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null) |
| 5258 | { | 5297 | { |
| 5259 | // In this case the comptime machinery will have evaluated the store instructions | 5298 | // In this case the comptime machinery will have evaluated the store instructions |
| ... | @@ -5629,9 +5668,7 @@ fn storeToInferredAllocComptime( | ... | @@ -5629,9 +5668,7 @@ fn storeToInferredAllocComptime( |
| 5629 | // There will be only one store_to_inferred_ptr because we are running at comptime. | 5668 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 5630 | // The alloc will turn into a Decl or a ComptimeAlloc. | 5669 | // The alloc will turn into a Decl or a ComptimeAlloc. |
| 5631 | const operand_val = try sema.resolveValue(operand) orelse { | 5670 | const operand_val = try sema.resolveValue(operand) orelse { |
| 5632 | return sema.failWithNeededComptime(block, src, .{ | 5671 | return sema.failWithNeededComptime(block, src, .{ .simple = .stored_to_comptime_var }); |
| 5633 | .needed_comptime_reason = "value being stored to a comptime variable must be comptime-known", | | |
| 5634 | }); | | |
| 5635 | }; | 5672 | }; |
| 5636 | const alloc_ty = try pt.ptrTypeSema(.{ | 5673 | const alloc_ty = try pt.ptrTypeSema(.{ |
| 5637 | .child = operand_ty.toIntern(), | 5674 | .child = operand_ty.toIntern(), |
| ... | @@ -5663,9 +5700,7 @@ fn storeToInferredAllocComptime( | ... | @@ -5663,9 +5700,7 @@ fn storeToInferredAllocComptime( |
| 5663 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5700 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5664 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5701 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5665 | const src = block.nodeOffset(inst_data.src_node); | 5702 | const src = block.nodeOffset(inst_data.src_node); |
| 5666 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ | 5703 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, .u32, .{ .simple = .operand_setEvalBranchQuota })); |
| 5667 | .needed_comptime_reason = "eval branch quota must be comptime-known", | | |
| 5668 | })); | | |
| 5669 | sema.branch_quota = @max(sema.branch_quota, quota); | 5704 | sema.branch_quota = @max(sema.branch_quota, quota); |
| 5670 | sema.allow_memoize = false; | 5705 | sema.allow_memoize = false; |
| 5671 | } | 5706 | } |
| ... | @@ -5794,9 +5829,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5794,9 +5829,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5794 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5829 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5795 | const src = block.nodeOffset(inst_data.src_node); | 5830 | const src = block.nodeOffset(inst_data.src_node); |
| 5796 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 5831 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 5797 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 5832 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ .simple = .compile_error_string }); |
| 5798 | .needed_comptime_reason = "compile error string must be comptime-known", | | |
| 5799 | }); | | |
| 5800 | return sema.fail(block, src, "{s}", .{msg}); | 5833 | return sema.fail(block, src, "{s}", .{msg}); |
| 5801 | } | 5834 | } |
| 5802 | | 5835 | |
| ... | @@ -5848,7 +5881,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5848,7 +5881,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5848 | // source location if we do it here. | 5881 | // source location if we do it here. |
| 5849 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); | 5882 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); |
| 5850 | | 5883 | |
| 5851 | if (block.is_comptime) { | 5884 | if (block.isComptime()) { |
| 5852 | return sema.fail(block, src, "encountered @panic at comptime", .{}); | 5885 | return sema.fail(block, src, "encountered @panic at comptime", .{}); |
| 5853 | } | 5886 | } |
| 5854 | | 5887 | |
| ... | @@ -5864,7 +5897,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5864,7 +5897,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5864 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5897 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5865 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; | 5898 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; |
| 5866 | const src = block.nodeOffset(src_node); | 5899 | const src = block.nodeOffset(src_node); |
| 5867 | if (block.is_comptime) | 5900 | if (block.isComptime()) |
| 5868 | return sema.fail(block, src, "encountered @trap at comptime", .{}); | 5901 | return sema.fail(block, src, "encountered @trap at comptime", .{}); |
| 5869 | _ = try block.addNoOp(.trap); | 5902 | _ = try block.addNoOp(.trap); |
| 5870 | } | 5903 | } |
| ... | @@ -5974,15 +6007,16 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5974,15 +6007,16 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5974 | var c_import_buf = std.ArrayList(u8).init(gpa); | 6007 | var c_import_buf = std.ArrayList(u8).init(gpa); |
| 5975 | defer c_import_buf.deinit(); | 6008 | defer c_import_buf.deinit(); |
| 5976 | | 6009 | |
| 5977 | const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } }; | | |
| 5978 | var child_block: Block = .{ | 6010 | var child_block: Block = .{ |
| 5979 | .parent = parent_block, | 6011 | .parent = parent_block, |
| 5980 | .sema = sema, | 6012 | .sema = sema, |
| 5981 | .namespace = parent_block.namespace, | 6013 | .namespace = parent_block.namespace, |
| 5982 | .instructions = .{}, | 6014 | .instructions = .{}, |
| 5983 | .inlining = parent_block.inlining, | 6015 | .inlining = parent_block.inlining, |
| 5984 | .is_comptime = true, | 6016 | .comptime_reason = .{ .reason = .{ |
| 5985 | .comptime_reason = &comptime_reason, | 6017 | .src = src, |
| | 6018 | .r = .{ .simple = .operand_cImport }, |
| | 6019 | } }, |
| 5986 | .c_import_buf = &c_import_buf, | 6020 | .c_import_buf = &c_import_buf, |
| 5987 | .runtime_cond = parent_block.runtime_cond, | 6021 | .runtime_cond = parent_block.runtime_cond, |
| 5988 | .runtime_loop = parent_block.runtime_loop, | 6022 | .runtime_loop = parent_block.runtime_loop, |
| ... | @@ -6073,7 +6107,7 @@ fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -6073,7 +6107,7 @@ fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) Comp |
| 6073 | return sema.failWithUseOfAsync(parent_block, src); | 6107 | return sema.failWithUseOfAsync(parent_block, src); |
| 6074 | } | 6108 | } |
| 6075 | | 6109 | |
| 6076 | fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_comptime: bool) CompileError!Air.Inst.Ref { | 6110 | fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6077 | const tracy = trace(@src()); | 6111 | const tracy = trace(@src()); |
| 6078 | defer tracy.end(); | 6112 | defer tracy.end(); |
| 6079 | | 6113 | |
| ... | @@ -6109,7 +6143,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -6109,7 +6143,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6109 | .instructions = .{}, | 6143 | .instructions = .{}, |
| 6110 | .label = &label, | 6144 | .label = &label, |
| 6111 | .inlining = parent_block.inlining, | 6145 | .inlining = parent_block.inlining, |
| 6112 | .is_comptime = parent_block.is_comptime or force_comptime, | | |
| 6113 | .comptime_reason = parent_block.comptime_reason, | 6146 | .comptime_reason = parent_block.comptime_reason, |
| 6114 | .is_typeof = parent_block.is_typeof, | 6147 | .is_typeof = parent_block.is_typeof, |
| 6115 | .want_safety = parent_block.want_safety, | 6148 | .want_safety = parent_block.want_safety, |
| ... | @@ -6143,7 +6176,7 @@ fn resolveBlockBody( | ... | @@ -6143,7 +6176,7 @@ fn resolveBlockBody( |
| 6143 | body_inst: Zir.Inst.Index, | 6176 | body_inst: Zir.Inst.Index, |
| 6144 | merges: *Block.Merges, | 6177 | merges: *Block.Merges, |
| 6145 | ) CompileError!Air.Inst.Ref { | 6178 | ) CompileError!Air.Inst.Ref { |
| 6146 | if (child_block.is_comptime) { | 6179 | if (child_block.isComptime()) { |
| 6147 | return sema.resolveInlineBody(child_block, body, body_inst); | 6180 | return sema.resolveInlineBody(child_block, body, body_inst); |
| 6148 | } else { | 6181 | } else { |
| 6149 | assert(sema.air_instructions.items(.tag)[@intFromEnum(merges.block_inst)] == .block); | 6182 | assert(sema.air_instructions.items(.tag)[@intFromEnum(merges.block_inst)] == .block); |
| ... | @@ -6303,7 +6336,7 @@ fn resolveAnalyzedBlock( | ... | @@ -6303,7 +6336,7 @@ fn resolveAnalyzedBlock( |
| 6303 | } | 6336 | } |
| 6304 | } | 6337 | } |
| 6305 | // It is impossible to have the number of results be > 1 in a comptime scope. | 6338 | // It is impossible to have the number of results be > 1 in a comptime scope. |
| 6306 | assert(!child_block.is_comptime); // Should already got a compile error in the condbr condition. | 6339 | assert(!child_block.isComptime()); // Should already got a compile error in the condbr condition. |
| 6307 | | 6340 | |
| 6308 | // Note that we'll always create an AIR block here, so `need_debug_scope` is irrelevant. | 6341 | // Note that we'll always create an AIR block here, so `need_debug_scope` is irrelevant. |
| 6309 | | 6342 | |
| ... | @@ -6425,9 +6458,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6425,9 +6458,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6425 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 6458 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6426 | | 6459 | |
| 6427 | const ptr = try sema.resolveInst(extra.exported); | 6460 | const ptr = try sema.resolveInst(extra.exported); |
| 6428 | const ptr_val = try sema.resolveConstDefinedValue(block, ptr_src, ptr, .{ | 6461 | const ptr_val = try sema.resolveConstDefinedValue(block, ptr_src, ptr, .{ .simple = .export_target }); |
| 6429 | .needed_comptime_reason = "export target must be comptime-known", | | |
| 6430 | }); | | |
| 6431 | const ptr_ty = ptr_val.typeOf(zcu); | 6462 | const ptr_ty = ptr_val.typeOf(zcu); |
| 6432 | | 6463 | |
| 6433 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 6464 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| ... | @@ -6553,17 +6584,13 @@ fn zirDisableInstrumentation(sema: *Sema) CompileError!void { | ... | @@ -6553,17 +6584,13 @@ fn zirDisableInstrumentation(sema: *Sema) CompileError!void { |
| 6553 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6584 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6554 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6585 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6555 | const src = block.builtinCallArgSrc(extra.node, 0); | 6586 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 6556 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ | 6587 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ .simple = .operand_setFloatMode }); |
| 6557 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", | | |
| 6558 | }); | | |
| 6559 | } | 6588 | } |
| 6560 | | 6589 | |
| 6561 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6590 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6562 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 6591 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 6563 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 6592 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6564 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ | 6593 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ .simple = .operand_setRuntimeSafety }); |
| 6565 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", | | |
| 6566 | }); | | |
| 6567 | } | 6594 | } |
| 6568 | | 6595 | |
| 6569 | fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6596 | fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -6650,7 +6677,7 @@ fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -6650,7 +6677,7 @@ fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) Com |
| 6650 | } | 6677 | } |
| 6651 | | 6678 | |
| 6652 | fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6679 | fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6653 | if (block.is_comptime or block.ownerModule().strip) return; | 6680 | if (block.isComptime() or block.ownerModule().strip) return; |
| 6654 | | 6681 | |
| 6655 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; | 6682 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; |
| 6656 | | 6683 | |
| ... | @@ -6676,7 +6703,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -6676,7 +6703,7 @@ fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 6676 | } | 6703 | } |
| 6677 | | 6704 | |
| 6678 | fn zirDbgEmptyStmt(_: *Sema, block: *Block, _: Zir.Inst.Index) CompileError!void { | 6705 | fn zirDbgEmptyStmt(_: *Sema, block: *Block, _: Zir.Inst.Index) CompileError!void { |
| 6679 | if (block.is_comptime or block.ownerModule().strip) return; | 6706 | if (block.isComptime() or block.ownerModule().strip) return; |
| 6680 | _ = try block.addNoOp(.dbg_empty_stmt); | 6707 | _ = try block.addNoOp(.dbg_empty_stmt); |
| 6681 | } | 6708 | } |
| 6682 | | 6709 | |
| ... | @@ -6699,7 +6726,7 @@ fn addDbgVar( | ... | @@ -6699,7 +6726,7 @@ fn addDbgVar( |
| 6699 | air_tag: Air.Inst.Tag, | 6726 | air_tag: Air.Inst.Tag, |
| 6700 | name: []const u8, | 6727 | name: []const u8, |
| 6701 | ) CompileError!void { | 6728 | ) CompileError!void { |
| 6702 | if (block.is_comptime or block.ownerModule().strip) return; | 6729 | if (block.isComptime() or block.ownerModule().strip) return; |
| 6703 | | 6730 | |
| 6704 | const pt = sema.pt; | 6731 | const pt = sema.pt; |
| 6705 | const zcu = pt.zcu; | 6732 | const zcu = pt.zcu; |
| ... | @@ -6931,7 +6958,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6931,7 +6958,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6931 | const zcu = pt.zcu; | 6958 | const zcu = pt.zcu; |
| 6932 | const gpa = sema.gpa; | 6959 | const gpa = sema.gpa; |
| 6933 | | 6960 | |
| 6934 | if (block.is_comptime or block.is_typeof) { | 6961 | if (block.isComptime() or block.is_typeof) { |
| 6935 | const index_val = try pt.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len); | 6962 | const index_val = try pt.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len); |
| 6936 | return Air.internedToRef(index_val.toIntern()); | 6963 | return Air.internedToRef(index_val.toIntern()); |
| 6937 | } | 6964 | } |
| ... | @@ -7134,7 +7161,7 @@ fn zirCall( | ... | @@ -7134,7 +7161,7 @@ fn zirCall( |
| 7134 | } | 7161 | } |
| 7135 | | 7162 | |
| 7136 | if (block.ownerModule().error_tracing and | 7163 | if (block.ownerModule().error_tracing and |
| 7137 | !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace)) | 7164 | !block.isComptime() and !block.is_typeof and (input_is_error or pop_error_return_trace)) |
| 7138 | { | 7165 | { |
| 7139 | const return_ty = sema.typeOf(call_inst); | 7166 | const return_ty = sema.typeOf(call_inst); |
| 7140 | if (modifier != .always_tail and return_ty.isNoReturn(zcu)) | 7167 | if (modifier != .always_tail and return_ty.isNoReturn(zcu)) |
| ... | @@ -7404,12 +7431,14 @@ const CallArgsInfo = union(enum) { | ... | @@ -7404,12 +7431,14 @@ const CallArgsInfo = union(enum) { |
| 7404 | }; | 7431 | }; |
| 7405 | | 7432 | |
| 7406 | // Generate args to comptime params in comptime block | 7433 | // Generate args to comptime params in comptime block |
| 7407 | const parent_comptime = block.is_comptime; | 7434 | const parent_comptime = block.comptime_reason; |
| 7408 | defer block.is_comptime = parent_comptime; | 7435 | defer block.comptime_reason = parent_comptime; |
| 7409 | // Note that we are indexing into parameters, not arguments, so use `arg_index` instead of `real_arg_idx` | 7436 | // Note that we are indexing into parameters, not arguments, so use `arg_index` instead of `real_arg_idx` |
| 7410 | if (arg_index < @min(param_count, 32) and func_ty_info.paramIsComptime(@intCast(arg_index))) { | 7437 | if (arg_index < @min(param_count, 32) and func_ty_info.paramIsComptime(@intCast(arg_index))) { |
| 7411 | block.is_comptime = true; | 7438 | block.comptime_reason = .{ .reason = .{ |
| 7412 | // TODO set comptime_reason | 7439 | .src = cai.argSrc(block, arg_index), |
| | 7440 | .r = .{ .simple = .comptime_param_arg }, |
| | 7441 | } }; |
| 7413 | } | 7442 | } |
| 7414 | // Give the arg its result type | 7443 | // Give the arg its result type |
| 7415 | const provide_param_ty = if (maybe_param_ty) |t| t else Type.generic_poison; | 7444 | const provide_param_ty = if (maybe_param_ty) |t| t else Type.generic_poison; |
| ... | @@ -7611,23 +7640,37 @@ fn analyzeCall( | ... | @@ -7611,23 +7640,37 @@ fn analyzeCall( |
| 7611 | | 7640 | |
| 7612 | const gpa = sema.gpa; | 7641 | const gpa = sema.gpa; |
| 7613 | | 7642 | |
| | 7643 | const func_ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrcInst(func)) |fn_decl_inst| .{ |
| | 7644 | .base_node_inst = fn_decl_inst, |
| | 7645 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| | 7646 | } else func_src; |
| | 7647 | |
| | 7648 | // If this is not `null`, the call is comptime. |
| | 7649 | var comptime_call_reason: ?BlockComptimeReason = cr: { |
| | 7650 | if (block.comptime_reason) |r| break :cr r; |
| | 7651 | if (modifier == .compile_time) break :cr .{ .reason = .{ |
| | 7652 | .src = call_src, |
| | 7653 | .r = .{ .simple = .comptime_call_modifier }, |
| | 7654 | } }; |
| | 7655 | break :cr null; |
| | 7656 | }; |
| | 7657 | |
| 7614 | const is_generic_call = func_ty_info.is_generic; | 7658 | const is_generic_call = func_ty_info.is_generic; |
| 7615 | var is_comptime_call = block.is_comptime or modifier == .compile_time; | 7659 | var is_inline_call = comptime_call_reason != null or modifier == .always_inline or func_ty_info.cc == .@"inline"; |
| 7616 | var is_inline_call = is_comptime_call or modifier == .always_inline or func_ty_info.cc == .@"inline"; | 7660 | if (!is_inline_call) { |
| 7617 | var comptime_reason: ?*const Block.ComptimeReason = null; | | |
| 7618 | if (!is_inline_call and !is_comptime_call) { | | |
| 7619 | if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) { | 7661 | if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) { |
| 7620 | is_comptime_call = true; | | |
| 7621 | is_inline_call = true; | 7662 | is_inline_call = true; |
| 7622 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7663 | comptime_call_reason = .{ .reason = .{ |
| 7623 | .func = func, | 7664 | .src = func_ret_ty_src, |
| 7624 | .func_src = func_src, | 7665 | .r = .{ .comptime_only = .{ |
| 7625 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7666 | .ty = .fromInterned(func_ty_info.return_type), |
| | 7667 | .msg = .ret_ty_call, |
| | 7668 | } }, |
| 7626 | } }; | 7669 | } }; |
| 7627 | } | 7670 | } |
| 7628 | } | 7671 | } |
| 7629 | | 7672 | |
| 7630 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { | 7673 | if (sema.func_is_naked and !is_inline_call) { |
| 7631 | const msg = msg: { | 7674 | const msg = msg: { |
| 7632 | const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); | 7675 | const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); |
| 7633 | errdefer msg.destroy(sema.gpa); | 7676 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -7642,6 +7685,7 @@ fn analyzeCall( | ... | @@ -7642,6 +7685,7 @@ fn analyzeCall( |
| 7642 | } | 7685 | } |
| 7643 | | 7686 | |
| 7644 | if (!is_inline_call and is_generic_call) { | 7687 | if (!is_inline_call and is_generic_call) { |
| | 7688 | var comptime_ret_ty: Type = undefined; |
| 7645 | if (sema.instantiateGenericCall( | 7689 | if (sema.instantiateGenericCall( |
| 7646 | block, | 7690 | block, |
| 7647 | func, | 7691 | func, |
| ... | @@ -7651,6 +7695,7 @@ fn analyzeCall( | ... | @@ -7651,6 +7695,7 @@ fn analyzeCall( |
| 7651 | args_info, | 7695 | args_info, |
| 7652 | call_tag, | 7696 | call_tag, |
| 7653 | call_dbg_node, | 7697 | call_dbg_node, |
| | 7698 | &comptime_ret_ty, |
| 7654 | )) |some| { | 7699 | )) |some| { |
| 7655 | return some; | 7700 | return some; |
| 7656 | } else |err| switch (err) { | 7701 | } else |err| switch (err) { |
| ... | @@ -7659,26 +7704,34 @@ fn analyzeCall( | ... | @@ -7659,26 +7704,34 @@ fn analyzeCall( |
| 7659 | }, | 7704 | }, |
| 7660 | error.ComptimeReturn => { | 7705 | error.ComptimeReturn => { |
| 7661 | is_inline_call = true; | 7706 | is_inline_call = true; |
| 7662 | is_comptime_call = true; | 7707 | comptime_call_reason = .{ .reason = .{ |
| 7663 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7708 | .src = func_ret_ty_src, |
| 7664 | .func = func, | 7709 | .r = .{ |
| 7665 | .func_src = func_src, | 7710 | .comptime_only = .{ |
| 7666 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7711 | .ty = comptime_ret_ty, |
| | 7712 | .msg = .ret_ty_generic_call, |
| | 7713 | }, |
| | 7714 | }, |
| 7667 | } }; | 7715 | } }; |
| 7668 | }, | 7716 | }, |
| 7669 | else => |e| return e, | 7717 | else => |e| return e, |
| 7670 | } | 7718 | } |
| 7671 | } | 7719 | } |
| 7672 | | 7720 | |
| | 7721 | const is_comptime_call = comptime_call_reason != null; |
| | 7722 | // `comptime_call_reason` shouldn't be mutated again |
| | 7723 | defer assert(is_comptime_call == (comptime_call_reason != null)); |
| | 7724 | |
| 7673 | if (is_comptime_call and modifier == .never_inline) { | 7725 | if (is_comptime_call and modifier == .never_inline) { |
| 7674 | return sema.fail(block, call_src, "unable to perform 'never_inline' call at compile-time", .{}); | 7726 | return sema.fail(block, call_src, "unable to perform 'never_inline' call at compile-time", .{}); |
| 7675 | } | 7727 | } |
| 7676 | | 7728 | |
| 7677 | const result: Air.Inst.Ref = if (is_inline_call) res: { | 7729 | const result: Air.Inst.Ref = if (is_inline_call) res: { |
| 7678 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ | 7730 | const old_comptime_reason = block.comptime_reason; |
| 7679 | .needed_comptime_reason = "function being called at comptime must be comptime-known", | 7731 | block.comptime_reason = comptime_call_reason; |
| 7680 | .block_comptime_reason = comptime_reason, | 7732 | defer block.comptime_reason = old_comptime_reason; |
| 7681 | }); | 7733 | |
| | 7734 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ .simple = .comptime_call_target }); |
| 7682 | const module_fn_index = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { | 7735 | const module_fn_index = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { |
| 7683 | .@"extern" => return sema.fail(block, call_src, "{s} call of extern function", .{ | 7736 | .@"extern" => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 7684 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), | 7737 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| ... | @@ -7767,8 +7820,7 @@ fn analyzeCall( | ... | @@ -7767,8 +7820,7 @@ fn analyzeCall( |
| 7767 | .label = null, | 7820 | .label = null, |
| 7768 | .inlining = &inlining, | 7821 | .inlining = &inlining, |
| 7769 | .is_typeof = block.is_typeof, | 7822 | .is_typeof = block.is_typeof, |
| 7770 | .is_comptime = is_comptime_call, | 7823 | .comptime_reason = if (is_comptime_call) .inlining_parent else null, |
| 7771 | .comptime_reason = comptime_reason, | | |
| 7772 | .error_return_trace_index = block.error_return_trace_index, | 7824 | .error_return_trace_index = block.error_return_trace_index, |
| 7773 | .runtime_cond = block.runtime_cond, | 7825 | .runtime_cond = block.runtime_cond, |
| 7774 | .runtime_loop = block.runtime_loop, | 7826 | .runtime_loop = block.runtime_loop, |
| ... | @@ -7857,11 +7909,16 @@ fn analyzeCall( | ... | @@ -7857,11 +7909,16 @@ fn analyzeCall( |
| 7857 | // on parameters, we must now do the same for the return type as we just did with | 7909 | // on parameters, we must now do the same for the return type as we just did with |
| 7858 | // each of the parameters, resolving the return type and providing it to the child | 7910 | // each of the parameters, resolving the return type and providing it to the child |
| 7859 | // `Sema` so that it can be used for the `ret_ptr` instruction. | 7911 | // `Sema` so that it can be used for the `ret_ptr` instruction. |
| 7860 | const ret_ty_inst = if (fn_info.ret_ty_body.len != 0) | | |
| 7861 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip) orelse return error.AnalysisFail) | | |
| 7862 | else | | |
| 7863 | try sema.resolveInst(fn_info.ret_ty_ref); | | |
| 7864 | const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } }; | 7912 | const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } }; |
| | 7913 | const ret_ty_inst = if (fn_info.ret_ty_body.len != 0) r: { |
| | 7914 | const old_child_comptime_reason = child_block.comptime_reason; |
| | 7915 | defer child_block.comptime_reason = old_child_comptime_reason; |
| | 7916 | child_block.comptime_reason = .{ .reason = .{ |
| | 7917 | .src = ret_ty_src, |
| | 7918 | .r = .{ .simple = .function_ret_ty }, |
| | 7919 | } }; |
| | 7920 | break :r try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip) orelse return error.AnalysisFail); |
| | 7921 | } else try sema.resolveInst(fn_info.ret_ty_ref); |
| 7865 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); | 7922 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); |
| 7866 | if (module_fn.analysisUnordered(ip).inferred_error_set) { | 7923 | if (module_fn.analysisUnordered(ip).inferred_error_set) { |
| 7867 | // Create a fresh inferred error set type for inline/comptime calls. | 7924 | // Create a fresh inferred error set type for inline/comptime calls. |
| ... | @@ -8136,23 +8193,18 @@ fn analyzeInlineCallArg( | ... | @@ -8136,23 +8193,18 @@ fn analyzeInlineCallArg( |
| 8136 | return casted_arg; | 8193 | return casted_arg; |
| 8137 | } | 8194 | } |
| 8138 | const arg_src = args_info.argSrc(arg_block, arg_i.*); | 8195 | const arg_src = args_info.argSrc(arg_block, arg_i.*); |
| 8139 | if (try Type.fromInterned(param_ty).comptimeOnlySema(ics.callee().pt)) { | 8196 | if (zir_tags[@intFromEnum(inst)] == .param_comptime) { |
| 8140 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ | 8197 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ .simple = .comptime_param_arg }); |
| 8141 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", | 8198 | } else if (!is_comptime_call and try Type.fromInterned(param_ty).comptimeOnlySema(ics.callee().pt)) { |
| 8142 | .block_comptime_reason = param_block.comptime_reason, | 8199 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ .comptime_only = .{ |
| 8143 | }); | 8200 | .ty = .fromInterned(param_ty), |
| 8144 | } else if (!is_comptime_call and zir_tags[@intFromEnum(inst)] == .param_comptime) { | 8201 | .msg = .param_ty_arg, |
| 8145 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ | 8202 | } }); |
| 8146 | .needed_comptime_reason = "parameter is comptime", | | |
| 8147 | }); | | |
| 8148 | } | 8203 | } |
| 8149 | | 8204 | |
| 8150 | if (is_comptime_call) { | 8205 | if (is_comptime_call) { |
| 8151 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); | 8206 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); |
| 8152 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ | 8207 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, null); |
| 8153 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", | | |
| 8154 | .block_comptime_reason = param_block.comptime_reason, | | |
| 8155 | }); | | |
| 8156 | switch (arg_val.toIntern()) { | 8208 | switch (arg_val.toIntern()) { |
| 8157 | .generic_poison, .generic_poison_type => { | 8209 | .generic_poison, .generic_poison_type => { |
| 8158 | // This function is currently evaluated as part of an as-of-yet unresolvable | 8210 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -8188,10 +8240,7 @@ fn analyzeInlineCallArg( | ... | @@ -8188,10 +8240,7 @@ fn analyzeInlineCallArg( |
| 8188 | | 8240 | |
| 8189 | if (is_comptime_call) { | 8241 | if (is_comptime_call) { |
| 8190 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 8242 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 8191 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ | 8243 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, null); |
| 8192 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", | | |
| 8193 | .block_comptime_reason = param_block.comptime_reason, | | |
| 8194 | }); | | |
| 8195 | switch (arg_val.toIntern()) { | 8244 | switch (arg_val.toIntern()) { |
| 8196 | .generic_poison, .generic_poison_type => { | 8245 | .generic_poison, .generic_poison_type => { |
| 8197 | // This function is currently evaluated as part of an as-of-yet unresolvable | 8246 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -8208,9 +8257,7 @@ fn analyzeInlineCallArg( | ... | @@ -8208,9 +8257,7 @@ fn analyzeInlineCallArg( |
| 8208 | memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern(); | 8257 | memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern(); |
| 8209 | } else { | 8258 | } else { |
| 8210 | if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) { | 8259 | if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) { |
| 8211 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ | 8260 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ .simple = .comptime_param_arg }); |
| 8212 | .needed_comptime_reason = "parameter is comptime", | | |
| 8213 | }); | | |
| 8214 | } | 8261 | } |
| 8215 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); | 8262 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 8216 | } | 8263 | } |
| ... | @@ -8237,15 +8284,18 @@ fn instantiateGenericCall( | ... | @@ -8237,15 +8284,18 @@ fn instantiateGenericCall( |
| 8237 | args_info: CallArgsInfo, | 8284 | args_info: CallArgsInfo, |
| 8238 | call_tag: Air.Inst.Tag, | 8285 | call_tag: Air.Inst.Tag, |
| 8239 | call_dbg_node: ?Zir.Inst.Index, | 8286 | call_dbg_node: ?Zir.Inst.Index, |
| | 8287 | /// Populated when `error.ComptimeReturn` is returned. |
| | 8288 | comptime_ret_ty: *Type, |
| 8240 | ) CompileError!Air.Inst.Ref { | 8289 | ) CompileError!Air.Inst.Ref { |
| 8241 | const pt = sema.pt; | 8290 | const pt = sema.pt; |
| 8242 | const zcu = pt.zcu; | 8291 | const zcu = pt.zcu; |
| 8243 | const gpa = sema.gpa; | 8292 | const gpa = sema.gpa; |
| 8244 | const ip = &zcu.intern_pool; | 8293 | const ip = &zcu.intern_pool; |
| 8245 | | 8294 | |
| 8246 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ | 8295 | // Generic function pointers are comptime-only types, so `func` is definitely comptime-known. |
| 8247 | .needed_comptime_reason = "generic function being called must be comptime-known", | 8296 | const func_val = (sema.resolveValue(func) catch unreachable).?; |
| 8248 | }); | 8297 | if (func_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, func_src); |
| | 8298 | |
| 8249 | const generic_owner = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { | 8299 | const generic_owner = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { |
| 8250 | .func => func_val.toIntern(), | 8300 | .func => func_val.toIntern(), |
| 8251 | .ptr => |ptr| ip.getNav(ptr.base_addr.nav).status.fully_resolved.val, | 8301 | .ptr => |ptr| ip.getNav(ptr.base_addr.nav).status.fully_resolved.val, |
| ... | @@ -8310,7 +8360,7 @@ fn instantiateGenericCall( | ... | @@ -8310,7 +8360,7 @@ fn instantiateGenericCall( |
| 8310 | .namespace = fn_nav.analysis.?.namespace, | 8360 | .namespace = fn_nav.analysis.?.namespace, |
| 8311 | .instructions = .{}, | 8361 | .instructions = .{}, |
| 8312 | .inlining = null, | 8362 | .inlining = null, |
| 8313 | .is_comptime = true, | 8363 | .comptime_reason = undefined, // set as needed |
| 8314 | .src_base_inst = fn_nav.analysis.?.zir_index, | 8364 | .src_base_inst = fn_nav.analysis.?.zir_index, |
| 8315 | .type_name_ctx = fn_nav.fqn, | 8365 | .type_name_ctx = fn_nav.fqn, |
| 8316 | }; | 8366 | }; |
| ... | @@ -8354,12 +8404,13 @@ fn instantiateGenericCall( | ... | @@ -8354,12 +8404,13 @@ fn instantiateGenericCall( |
| 8354 | child_sema.generic_call_src = prev_generic_call_src; | 8404 | child_sema.generic_call_src = prev_generic_call_src; |
| 8355 | } | 8405 | } |
| 8356 | | 8406 | |
| | 8407 | const param_ty_src = child_block.tokenOffset(param_data.src_tok); |
| | 8408 | child_block.comptime_reason = .{ .reason = .{ |
| | 8409 | .src = param_ty_src, |
| | 8410 | .r = .{ .simple = .type }, |
| | 8411 | } }; |
| 8357 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); | 8412 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); |
| 8358 | break :param_ty try child_sema.analyzeAsType( | 8413 | break :param_ty try child_sema.analyzeAsType(&child_block, param_ty_src, param_ty_inst); |
| 8359 | &child_block, | | |
| 8360 | child_block.tokenOffset(param_data.src_tok), | | |
| 8361 | param_ty_inst, | | |
| 8362 | ); | | |
| 8363 | }, | 8414 | }, |
| 8364 | else => unreachable, | 8415 | else => unreachable, |
| 8365 | } | 8416 | } |
| ... | @@ -8452,6 +8503,10 @@ fn instantiateGenericCall( | ... | @@ -8452,6 +8503,10 @@ fn instantiateGenericCall( |
| 8452 | | 8503 | |
| 8453 | // We've already handled parameters, so don't resolve the whole body. Instead, just | 8504 | // We've already handled parameters, so don't resolve the whole body. Instead, just |
| 8454 | // do the instructions after the params (i.e. the func itself). | 8505 | // do the instructions after the params (i.e. the func itself). |
| | 8506 | child_block.comptime_reason = .{ .reason = .{ |
| | 8507 | .src = call_src, |
| | 8508 | .r = .{ .simple = .type }, |
| | 8509 | } }; |
| 8455 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); | 8510 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); |
| 8456 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); | 8511 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 8457 | | 8512 | |
| ... | @@ -8465,6 +8520,7 @@ fn instantiateGenericCall( | ... | @@ -8465,6 +8520,7 @@ fn instantiateGenericCall( |
| 8465 | // If the call evaluated to a return type that requires comptime, never mind | 8520 | // If the call evaluated to a return type that requires comptime, never mind |
| 8466 | // our generic instantiation. Instead we need to perform a comptime call. | 8521 | // our generic instantiation. Instead we need to perform a comptime call. |
| 8467 | if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) { | 8522 | if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) { |
| | 8523 | comptime_ret_ty.* = .fromInterned(func_ty_info.return_type); |
| 8468 | return error.ComptimeReturn; | 8524 | return error.ComptimeReturn; |
| 8469 | } | 8525 | } |
| 8470 | // Similarly, if the call evaluated to a generic type we need to instead | 8526 | // Similarly, if the call evaluated to a generic type we need to instead |
| ... | @@ -8622,9 +8678,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8622,9 +8678,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8622 | const len_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 8678 | const len_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8623 | const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 8679 | const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 8624 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8680 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8625 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ | 8681 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ .simple = .vector_length })); |
| 8626 | .needed_comptime_reason = "vector length must be comptime-known", | | |
| 8627 | })); | | |
| 8628 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); | 8682 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); |
| 8629 | try sema.checkVectorElemType(block, elem_type_src, elem_type); | 8683 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 8630 | const vector_type = try sema.pt.vectorType(.{ | 8684 | const vector_type = try sema.pt.vectorType(.{ |
| ... | @@ -8642,9 +8696,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8642,9 +8696,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8642 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8696 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8643 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); | 8697 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8644 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); | 8698 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8645 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ | 8699 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ .simple = .array_length }); |
| 8646 | .needed_comptime_reason = "array length must be comptime-known", | | |
| 8647 | }); | | |
| 8648 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | 8700 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); |
| 8649 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8701 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8650 | const array_ty = try sema.pt.arrayType(.{ | 8702 | const array_ty = try sema.pt.arrayType(.{ |
| ... | @@ -8664,16 +8716,12 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8664,16 +8716,12 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8664 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); | 8716 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8665 | const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node }); | 8717 | const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node }); |
| 8666 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); | 8718 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8667 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ | 8719 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ .simple = .array_length }); |
| 8668 | .needed_comptime_reason = "array length must be comptime-known", | | |
| 8669 | }); | | |
| 8670 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); | 8720 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); |
| 8671 | try sema.validateArrayElemType(block, elem_type, elem_src); | 8721 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8672 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); | 8722 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 8673 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); | 8723 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 8674 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ | 8724 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ .simple = .array_sentinel }); |
| 8675 | .needed_comptime_reason = "array sentinel value must be comptime-known", | | |
| 8676 | }); | | |
| 8677 | const array_ty = try sema.pt.arrayType(.{ | 8725 | const array_ty = try sema.pt.arrayType(.{ |
| 8678 | .len = len, | 8726 | .len = len, |
| 8679 | .sentinel = sentinel_val.toIntern(), | 8727 | .sentinel = sentinel_val.toIntern(), |
| ... | @@ -9071,9 +9119,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -9071,9 +9119,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9071 | } | 9119 | } |
| 9072 | | 9120 | |
| 9073 | if (dest_ty.intTagType(zcu).zigTypeTag(zcu) == .comptime_int) { | 9121 | if (dest_ty.intTagType(zcu).zigTypeTag(zcu) == .comptime_int) { |
| 9074 | return sema.failWithNeededComptime(block, operand_src, .{ | 9122 | return sema.failWithNeededComptime(block, operand_src, .{ .simple = .casted_to_comptime_enum }); |
| 9075 | .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known", | | |
| 9076 | }); | | |
| 9077 | } | 9123 | } |
| 9078 | | 9124 | |
| 9079 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { | 9125 | if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| { |
| ... | @@ -9487,9 +9533,7 @@ fn zirFunc( | ... | @@ -9487,9 +9533,7 @@ fn zirFunc( |
| 9487 | const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_body_len); | 9533 | const ret_ty_body = sema.code.bodySlice(extra_index, extra.data.ret_body_len); |
| 9488 | extra_index += ret_ty_body.len; | 9534 | extra_index += ret_ty_body.len; |
| 9489 | | 9535 | |
| 9490 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ | 9536 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{ .simple = .function_ret_ty }); |
| 9491 | .needed_comptime_reason = "return type must be comptime-known", | | |
| 9492 | }); | | |
| 9493 | break :blk ret_ty_val.toType(); | 9537 | break :blk ret_ty_val.toType(); |
| 9494 | }, | 9538 | }, |
| 9495 | }; | 9539 | }; |
| ... | @@ -9556,7 +9600,7 @@ fn resolveGenericBody( | ... | @@ -9556,7 +9600,7 @@ fn resolveGenericBody( |
| 9556 | body: []const Zir.Inst.Index, | 9600 | body: []const Zir.Inst.Index, |
| 9557 | func_inst: Zir.Inst.Index, | 9601 | func_inst: Zir.Inst.Index, |
| 9558 | dest_ty: Type, | 9602 | dest_ty: Type, |
| 9559 | reason: NeededComptimeReason, | 9603 | reason: ComptimeReason, |
| 9560 | ) !Value { | 9604 | ) !Value { |
| 9561 | assert(body.len != 0); | 9605 | assert(body.len != 0); |
| 9562 | | 9606 | |
| ... | @@ -9894,7 +9938,7 @@ fn funcCommon( | ... | @@ -9894,7 +9938,7 @@ fn funcCommon( |
| 9894 | }; | 9938 | }; |
| 9895 | return sema.failWithOwnedErrorMsg(block, msg); | 9939 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9896 | } | 9940 | } |
| 9897 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { | 9941 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.isComptime()) { |
| 9898 | const msg = msg: { | 9942 | const msg = msg: { |
| 9899 | const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{ | 9943 | const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{ |
| 9900 | param_ty.fmt(pt), | 9944 | param_ty.fmt(pt), |
| ... | @@ -10132,7 +10176,7 @@ fn finishFunc( | ... | @@ -10132,7 +10176,7 @@ fn finishFunc( |
| 10132 | | 10176 | |
| 10133 | // If the return type is comptime-only but not dependent on parameters then | 10177 | // If the return type is comptime-only but not dependent on parameters then |
| 10134 | // all parameter types also need to be comptime. | 10178 | // all parameter types also need to be comptime. |
| 10135 | if (is_source_decl and opt_func_index != .none and ret_ty_requires_comptime and !block.is_comptime) comptime_check: { | 10179 | if (is_source_decl and opt_func_index != .none and ret_ty_requires_comptime and !block.isComptime()) comptime_check: { |
| 10136 | for (block.params.items(.is_comptime)) |is_comptime| { | 10180 | for (block.params.items(.is_comptime)) |is_comptime| { |
| 10137 | if (!is_comptime) break; | 10181 | if (!is_comptime) break; |
| 10138 | } else break :comptime_check; | 10182 | } else break :comptime_check; |
| ... | @@ -10547,9 +10591,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10547,9 +10591,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10547 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 10591 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10548 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10592 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10549 | const object = try sema.resolveInst(extra.lhs); | 10593 | const object = try sema.resolveInst(extra.lhs); |
| 10550 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10594 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name }); |
| 10551 | .needed_comptime_reason = "field name must be comptime-known", | | |
| 10552 | }); | | |
| 10553 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 10595 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 10554 | } | 10596 | } |
| 10555 | | 10597 | |
| ... | @@ -10562,9 +10604,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10562,9 +10604,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10562 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 10604 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10563 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10605 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10564 | const object_ptr = try sema.resolveInst(extra.lhs); | 10606 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10565 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10607 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name }); |
| 10566 | .needed_comptime_reason = "field name must be comptime-known", | | |
| 10567 | }); | | |
| 10568 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); | 10608 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 10569 | } | 10609 | } |
| 10570 | | 10610 | |
| ... | @@ -11923,7 +11963,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11923,7 +11963,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11923 | .instructions = .{}, | 11963 | .instructions = .{}, |
| 11924 | .label = &label, | 11964 | .label = &label, |
| 11925 | .inlining = block.inlining, | 11965 | .inlining = block.inlining, |
| 11926 | .is_comptime = block.is_comptime, | | |
| 11927 | .comptime_reason = block.comptime_reason, | 11966 | .comptime_reason = block.comptime_reason, |
| 11928 | .is_typeof = block.is_typeof, | 11967 | .is_typeof = block.is_typeof, |
| 11929 | .c_import_buf = block.c_import_buf, | 11968 | .c_import_buf = block.c_import_buf, |
| ... | @@ -12027,11 +12066,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -12027,11 +12066,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 12027 | }; | 12066 | }; |
| 12028 | } | 12067 | } |
| 12029 | | 12068 | |
| 12030 | if (child_block.is_comptime) { | 12069 | if (child_block.isComptime()) { |
| 12031 | _ = try sema.resolveConstDefinedValue(&child_block, main_operand_src, raw_operand_val, .{ | 12070 | _ = try sema.resolveConstDefinedValue(&child_block, main_operand_src, raw_operand_val, null); |
| 12032 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", | | |
| 12033 | .block_comptime_reason = child_block.comptime_reason, | | |
| 12034 | }); | | |
| 12035 | unreachable; | 12071 | unreachable; |
| 12036 | } | 12072 | } |
| 12037 | | 12073 | |
| ... | @@ -12148,7 +12184,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12148,7 +12184,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12148 | | 12184 | |
| 12149 | const operand_ty = sema.typeOf(val); | 12185 | const operand_ty = sema.typeOf(val); |
| 12150 | | 12186 | |
| 12151 | if (extra.data.bits.has_continue and !block.is_comptime) { | 12187 | if (extra.data.bits.has_continue and !block.isComptime()) { |
| 12152 | // Even if the operand is comptime-known, this `switch` is runtime. | 12188 | // Even if the operand is comptime-known, this `switch` is runtime. |
| 12153 | if (try operand_ty.comptimeOnlySema(pt)) { | 12189 | if (try operand_ty.comptimeOnlySema(pt)) { |
| 12154 | return sema.failWithOwnedErrorMsg(block, msg: { | 12190 | return sema.failWithOwnedErrorMsg(block, msg: { |
| ... | @@ -12707,7 +12743,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12707,7 +12743,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12707 | .instructions = .{}, | 12743 | .instructions = .{}, |
| 12708 | .label = &label, | 12744 | .label = &label, |
| 12709 | .inlining = block.inlining, | 12745 | .inlining = block.inlining, |
| 12710 | .is_comptime = block.is_comptime, | | |
| 12711 | .comptime_reason = block.comptime_reason, | 12746 | .comptime_reason = block.comptime_reason, |
| 12712 | .is_typeof = block.is_typeof, | 12747 | .is_typeof = block.is_typeof, |
| 12713 | .c_import_buf = block.c_import_buf, | 12748 | .c_import_buf = block.c_import_buf, |
| ... | @@ -12790,11 +12825,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12790,11 +12825,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12790 | }, | 12825 | }, |
| 12791 | } | 12826 | } |
| 12792 | | 12827 | |
| 12793 | if (child_block.is_comptime) { | 12828 | if (child_block.isComptime()) { |
| 12794 | _ = try sema.resolveConstDefinedValue(&child_block, operand_src, operand.simple.cond, .{ | 12829 | _ = try sema.resolveConstDefinedValue(&child_block, operand_src, operand.simple.cond, null); |
| 12795 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", | | |
| 12796 | .block_comptime_reason = child_block.comptime_reason, | | |
| 12797 | }); | | |
| 12798 | unreachable; | 12830 | unreachable; |
| 12799 | } | 12831 | } |
| 12800 | | 12832 | |
| ... | @@ -13582,10 +13614,7 @@ fn resolveSwitchComptimeLoop( | ... | @@ -13582,10 +13614,7 @@ fn resolveSwitchComptimeLoop( |
| 13582 | | 13614 | |
| 13583 | const cond_ref = try sema.switchCond(child_block, src, val); | 13615 | const cond_ref = try sema.switchCond(child_block, src, val); |
| 13584 | | 13616 | |
| 13585 | cond_val = try sema.resolveConstDefinedValue(child_block, src, cond_ref, .{ | 13617 | cond_val = try sema.resolveConstDefinedValue(child_block, src, cond_ref, null); |
| 13586 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", | | |
| 13587 | .block_comptime_reason = child_block.comptime_reason, | | |
| 13588 | }); | | |
| 13589 | spa.operand = .{ .simple = .{ | 13618 | spa.operand = .{ .simple = .{ |
| 13590 | .by_val = val, | 13619 | .by_val = val, |
| 13591 | .by_ref = ref, | 13620 | .by_ref = ref, |
| ... | @@ -13825,9 +13854,7 @@ fn resolveSwitchItemVal( | ... | @@ -13825,9 +13854,7 @@ fn resolveSwitchItemVal( |
| 13825 | | 13854 | |
| 13826 | const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src); | 13855 | const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src); |
| 13827 | | 13856 | |
| 13828 | const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{ | 13857 | const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{ .simple = .switch_item }); |
| 13829 | .needed_comptime_reason = "switch prong values must be comptime-known", | | |
| 13830 | }); | | |
| 13831 | | 13858 | |
| 13832 | const val = try sema.resolveLazyValue(maybe_lazy); | 13859 | const val = try sema.resolveLazyValue(maybe_lazy); |
| 13833 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { | 13860 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { |
| ... | @@ -14295,9 +14322,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14295,9 +14322,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14295 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 14322 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14296 | const name_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 14323 | const name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14297 | const ty = try sema.resolveType(block, ty_src, extra.lhs); | 14324 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 14298 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ | 14325 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ .simple = .field_name }); |
| 14299 | .needed_comptime_reason = "field name must be comptime-known", | | |
| 14300 | }); | | |
| 14301 | try ty.resolveFields(pt); | 14326 | try ty.resolveFields(pt); |
| 14302 | const ip = &zcu.intern_pool; | 14327 | const ip = &zcu.intern_pool; |
| 14303 | | 14328 | |
| ... | @@ -14344,9 +14369,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -14344,9 +14369,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 14344 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 14369 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14345 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 14370 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14346 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 14371 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 14347 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ | 14372 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ .simple = .decl_name }); |
| 14348 | .needed_comptime_reason = "decl name must be comptime-known", | | |
| 14349 | }); | | |
| 14350 | | 14373 | |
| 14351 | try sema.checkNamespaceType(block, lhs_src, container_type); | 14374 | try sema.checkNamespaceType(block, lhs_src, container_type); |
| 14352 | | 14375 | |
| ... | @@ -14399,9 +14422,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -14399,9 +14422,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 14399 | const pt = sema.pt; | 14422 | const pt = sema.pt; |
| 14400 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14423 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14401 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 14424 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14402 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 14425 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ .simple = .operand_embedFile }); |
| 14403 | .needed_comptime_reason = "file path name must be comptime-known", | | |
| 14404 | }); | | |
| 14405 | | 14426 | |
| 14406 | if (name.len == 0) { | 14427 | if (name.len == 0) { |
| 14407 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | 14428 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); |
| ... | @@ -14985,7 +15006,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14985,7 +15006,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14985 | | 15006 | |
| 14986 | const resolved_elem_ty = t: { | 15007 | const resolved_elem_ty = t: { |
| 14987 | var trash_block = block.makeSubBlock(); | 15008 | var trash_block = block.makeSubBlock(); |
| 14988 | trash_block.is_comptime = false; | 15009 | trash_block.comptime_reason = null; |
| 14989 | defer trash_block.instructions.deinit(sema.gpa); | 15010 | defer trash_block.instructions.deinit(sema.gpa); |
| 14990 | | 15011 | |
| 14991 | const instructions = [_]Air.Inst.Ref{ | 15012 | const instructions = [_]Air.Inst.Ref{ |
| ... | @@ -15268,9 +15289,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins | ... | @@ -15268,9 +15289,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 15268 | const ptr_info = operand_ty.ptrInfo(zcu); | 15289 | const ptr_info = operand_ty.ptrInfo(zcu); |
| 15269 | switch (ptr_info.flags.size) { | 15290 | switch (ptr_info.flags.size) { |
| 15270 | .Slice => { | 15291 | .Slice => { |
| 15271 | const val = try sema.resolveConstDefinedValue(block, src, operand, .{ | 15292 | const val = try sema.resolveConstDefinedValue(block, src, operand, .{ .simple = .slice_cat_operand }); |
| 15272 | .needed_comptime_reason = "slice value being concatenated must be comptime-known", | | |
| 15273 | }); | | |
| 15274 | return Type.ArrayInfo{ | 15293 | return Type.ArrayInfo{ |
| 15275 | .elem_type = Type.fromInterned(ptr_info.child), | 15294 | .elem_type = Type.fromInterned(ptr_info.child), |
| 15276 | .sentinel = switch (ptr_info.sentinel) { | 15295 | .sentinel = switch (ptr_info.sentinel) { |
| ... | @@ -15431,9 +15450,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15431,9 +15450,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15431 | | 15450 | |
| 15432 | if (lhs_ty.isTuple(zcu)) { | 15451 | if (lhs_ty.isTuple(zcu)) { |
| 15433 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 15452 | // In `**` rhs must be comptime-known, but lhs can be runtime-known |
| 15434 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ | 15453 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ .simple = .array_mul_factor }); |
| 15435 | .needed_comptime_reason = "array multiplication factor must be comptime-known", | | |
| 15436 | }); | | |
| 15437 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); | 15454 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); |
| 15438 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); | 15455 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); |
| 15439 | } | 15456 | } |
| ... | @@ -15455,9 +15472,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15455,9 +15472,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15455 | }; | 15472 | }; |
| 15456 | | 15473 | |
| 15457 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 15474 | // In `**` rhs must be comptime-known, but lhs can be runtime-known |
| 15458 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ | 15475 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{ .simple = .array_mul_factor }); |
| 15459 | .needed_comptime_reason = "array multiplication factor must be comptime-known", | | |
| 15460 | }); | | |
| 15461 | | 15476 | |
| 15462 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch | 15477 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch |
| 15463 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); | 15478 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| ... | @@ -17635,12 +17650,9 @@ fn zirAsm( | ... | @@ -17635,12 +17650,9 @@ fn zirAsm( |
| 17635 | const is_global_assembly = sema.func_index == .none; | 17650 | const is_global_assembly = sema.func_index == .none; |
| 17636 | const zir_tags = sema.code.instructions.items(.tag); | 17651 | const zir_tags = sema.code.instructions.items(.tag); |
| 17637 | | 17652 | |
| 17638 | const asm_source: []const u8 = if (tmpl_is_expr) blk: { | 17653 | const asm_source: []const u8 = if (tmpl_is_expr) s: { |
| 17639 | const tmpl: Zir.Inst.Ref = @enumFromInt(@intFromEnum(extra.data.asm_source)); | 17654 | const tmpl: Zir.Inst.Ref = @enumFromInt(@intFromEnum(extra.data.asm_source)); |
| 17640 | const s: []const u8 = try sema.resolveConstString(block, src, tmpl, .{ | 17655 | break :s try sema.resolveConstString(block, src, tmpl, .{ .simple = .inline_assembly_code }); |
| 17641 | .needed_comptime_reason = "assembly code must be comptime-known", | | |
| 17642 | }); | | |
| 17643 | break :blk s; | | |
| 17644 | } else sema.code.nullTerminatedString(extra.data.asm_source); | 17656 | } else sema.code.nullTerminatedString(extra.data.asm_source); |
| 17645 | | 17657 | |
| 17646 | if (is_global_assembly) { | 17658 | if (is_global_assembly) { |
| ... | @@ -18203,7 +18215,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -18203,7 +18215,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 18203 | return sema.failWithOwnedErrorMsg(block, msg); | 18215 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18204 | } | 18216 | } |
| 18205 | | 18217 | |
| 18206 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { | 18218 | if (!block.is_typeof and !block.isComptime() and sema.func_index != .none) { |
| 18207 | const msg = msg: { | 18219 | const msg = msg: { |
| 18208 | const name = name: { | 18220 | const name = name: { |
| 18209 | const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?; | 18221 | const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?; |
| ... | @@ -18244,7 +18256,7 @@ fn zirRetAddr( | ... | @@ -18244,7 +18256,7 @@ fn zirRetAddr( |
| 18244 | extended: Zir.Inst.Extended.InstData, | 18256 | extended: Zir.Inst.Extended.InstData, |
| 18245 | ) CompileError!Air.Inst.Ref { | 18257 | ) CompileError!Air.Inst.Ref { |
| 18246 | _ = extended; | 18258 | _ = extended; |
| 18247 | if (block.is_comptime) { | 18259 | if (block.isComptime()) { |
| 18248 | // TODO: we could give a meaningful lazy value here. #14938 | 18260 | // TODO: we could give a meaningful lazy value here. #14938 |
| 18249 | return sema.pt.intRef(Type.usize, 0); | 18261 | return sema.pt.intRef(Type.usize, 0); |
| 18250 | } else { | 18262 | } else { |
| ... | @@ -19342,7 +19354,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -19342,7 +19354,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 19342 | .namespace = block.namespace, | 19354 | .namespace = block.namespace, |
| 19343 | .instructions = .{}, | 19355 | .instructions = .{}, |
| 19344 | .inlining = block.inlining, | 19356 | .inlining = block.inlining, |
| 19345 | .is_comptime = false, | 19357 | .comptime_reason = null, |
| 19346 | .is_typeof = true, | 19358 | .is_typeof = true, |
| 19347 | .want_safety = false, | 19359 | .want_safety = false, |
| 19348 | .error_return_trace_index = block.error_return_trace_index, | 19360 | .error_return_trace_index = block.error_return_trace_index, |
| ... | @@ -19422,7 +19434,7 @@ fn zirTypeofPeer( | ... | @@ -19422,7 +19434,7 @@ fn zirTypeofPeer( |
| 19422 | .namespace = block.namespace, | 19434 | .namespace = block.namespace, |
| 19423 | .instructions = .{}, | 19435 | .instructions = .{}, |
| 19424 | .inlining = block.inlining, | 19436 | .inlining = block.inlining, |
| 19425 | .is_comptime = false, | 19437 | .comptime_reason = null, |
| 19426 | .is_typeof = true, | 19438 | .is_typeof = true, |
| 19427 | .runtime_cond = block.runtime_cond, | 19439 | .runtime_cond = block.runtime_cond, |
| 19428 | .runtime_loop = block.runtime_loop, | 19440 | .runtime_loop = block.runtime_loop, |
| ... | @@ -19980,7 +19992,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label | ... | @@ -19980,7 +19992,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label |
| 19980 | .instructions = .{}, | 19992 | .instructions = .{}, |
| 19981 | .label = &labeled_block.label, | 19993 | .label = &labeled_block.label, |
| 19982 | .inlining = block.inlining, | 19994 | .inlining = block.inlining, |
| 19983 | .is_comptime = block.is_comptime, | 19995 | .comptime_reason = block.comptime_reason, |
| 19984 | .src_base_inst = block.src_base_inst, | 19996 | .src_base_inst = block.src_base_inst, |
| 19985 | .type_name_ctx = block.type_name_ctx, | 19997 | .type_name_ctx = block.type_name_ctx, |
| 19986 | }, | 19998 | }, |
| ... | @@ -20013,7 +20025,7 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -20013,7 +20025,7 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 20013 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; | 20025 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; |
| 20014 | const src = block.nodeOffset(inst_data.src_node); | 20026 | const src = block.nodeOffset(inst_data.src_node); |
| 20015 | | 20027 | |
| 20016 | if (block.is_comptime) { | 20028 | if (block.isComptime()) { |
| 20017 | return sema.fail(block, src, "reached unreachable code", .{}); | 20029 | return sema.fail(block, src, "reached unreachable code", .{}); |
| 20018 | } | 20030 | } |
| 20019 | // TODO Add compile error for @optimizeFor occurring too late in a scope. | 20031 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| ... | @@ -20066,7 +20078,7 @@ fn zirRetImplicit( | ... | @@ -20066,7 +20078,7 @@ fn zirRetImplicit( |
| 20066 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; | 20078 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| 20067 | const r_brace_src = block.tokenOffset(inst_data.src_tok); | 20079 | const r_brace_src = block.tokenOffset(inst_data.src_tok); |
| 20068 | if (block.inlining == null and sema.func_is_naked) { | 20080 | if (block.inlining == null and sema.func_is_naked) { |
| 20069 | assert(!block.is_comptime); | 20081 | assert(!block.isComptime()); |
| 20070 | if (block.wantSafety()) { | 20082 | if (block.wantSafety()) { |
| 20071 | // Calling a safety function from a naked function would not be legal. | 20083 | // Calling a safety function from a naked function would not be legal. |
| 20072 | _ = try block.addNoOp(.trap); | 20084 | _ = try block.addNoOp(.trap); |
| ... | @@ -20123,7 +20135,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -20123,7 +20135,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 20123 | const src = block.nodeOffset(inst_data.src_node); | 20135 | const src = block.nodeOffset(inst_data.src_node); |
| 20124 | const ret_ptr = try sema.resolveInst(inst_data.operand); | 20136 | const ret_ptr = try sema.resolveInst(inst_data.operand); |
| 20125 | | 20137 | |
| 20126 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { | 20138 | if (block.isComptime() or block.inlining != null or sema.func_is_naked) { |
| 20127 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); | 20139 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); |
| 20128 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); | 20140 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); |
| 20129 | } | 20141 | } |
| ... | @@ -20215,7 +20227,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -20215,7 +20227,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 20215 | if (!block.ownerModule().error_tracing) return; | 20227 | if (!block.ownerModule().error_tracing) return; |
| 20216 | | 20228 | |
| 20217 | // This is only relevant at runtime. | 20229 | // This is only relevant at runtime. |
| 20218 | if (block.is_comptime or block.is_typeof) return; | 20230 | if (block.isComptime() or block.is_typeof) return; |
| 20219 | | 20231 | |
| 20220 | const save_index = inst_data.operand == .none or b: { | 20232 | const save_index = inst_data.operand == .none or b: { |
| 20221 | const operand = try sema.resolveInst(inst_data.operand); | 20233 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | @@ -20268,7 +20280,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_ | ... | @@ -20268,7 +20280,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_ |
| 20268 | | 20280 | |
| 20269 | const operand = try sema.resolveInstAllowNone(operand_zir); | 20281 | const operand = try sema.resolveInstAllowNone(operand_zir); |
| 20270 | | 20282 | |
| 20271 | if (start_block.is_comptime or start_block.is_typeof) { | 20283 | if (start_block.isComptime() or start_block.is_typeof) { |
| 20272 | const is_non_error = if (operand != .none) blk: { | 20284 | const is_non_error = if (operand != .none) blk: { |
| 20273 | const is_non_error_inst = try sema.analyzeIsNonErr(start_block, src, operand); | 20285 | const is_non_error_inst = try sema.analyzeIsNonErr(start_block, src, operand); |
| 20274 | const cond_val = try sema.resolveDefinedValue(start_block, src, is_non_error_inst); | 20286 | const cond_val = try sema.resolveDefinedValue(start_block, src, is_non_error_inst); |
| ... | @@ -20345,10 +20357,8 @@ fn analyzeRet( | ... | @@ -20345,10 +20357,8 @@ fn analyzeRet( |
| 20345 | }; | 20357 | }; |
| 20346 | | 20358 | |
| 20347 | if (block.inlining) |inlining| { | 20359 | if (block.inlining) |inlining| { |
| 20348 | if (block.is_comptime) { | 20360 | if (block.isComptime()) { |
| 20349 | const ret_val = try sema.resolveConstValue(block, operand_src, operand, .{ | 20361 | const ret_val = try sema.resolveConstValue(block, operand_src, operand, null); |
| 20350 | .needed_comptime_reason = "value being returned at comptime must be comptime-known", | | |
| 20351 | }); | | |
| 20352 | inlining.comptime_result = operand; | 20362 | inlining.comptime_result = operand; |
| 20353 | | 20363 | |
| 20354 | if (sema.fn_ret_ty.isError(zcu) and ret_val.getErrorName(zcu) != .none) { | 20364 | if (sema.fn_ret_ty.isError(zcu) and ret_val.getErrorName(zcu) != .none) { |
| ... | @@ -20362,7 +20372,7 @@ fn analyzeRet( | ... | @@ -20362,7 +20372,7 @@ fn analyzeRet( |
| 20362 | try inlining.merges.br_list.append(sema.gpa, br_inst.toIndex().?); | 20372 | try inlining.merges.br_list.append(sema.gpa, br_inst.toIndex().?); |
| 20363 | try inlining.merges.src_locs.append(sema.gpa, operand_src); | 20373 | try inlining.merges.src_locs.append(sema.gpa, operand_src); |
| 20364 | return; | 20374 | return; |
| 20365 | } else if (block.is_comptime) { | 20375 | } else if (block.isComptime()) { |
| 20366 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); | 20376 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); |
| 20367 | } else if (sema.func_is_naked) { | 20377 | } else if (sema.func_is_naked) { |
| 20368 | const msg = msg: { | 20378 | const msg = msg: { |
| ... | @@ -20436,9 +20446,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20436,9 +20446,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20436 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 20446 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 20437 | extra_i += 1; | 20447 | extra_i += 1; |
| 20438 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); | 20448 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 20439 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ | 20449 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ .simple = .pointer_sentinel }); |
| 20440 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", | | |
| 20441 | }); | | |
| 20442 | try checkSentinelType(sema, block, sentinel_src, elem_ty); | 20450 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 20443 | break :blk val.toIntern(); | 20451 | break :blk val.toIntern(); |
| 20444 | } else .none; | 20452 | } else .none; |
| ... | @@ -20447,9 +20455,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20447,9 +20455,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20447 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 20455 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 20448 | extra_i += 1; | 20456 | extra_i += 1; |
| 20449 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); | 20457 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); |
| 20450 | const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ | 20458 | const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ .simple = .@"align" }); |
| 20451 | .needed_comptime_reason = "pointer alignment must be comptime-known", | | |
| 20452 | }); | | |
| 20453 | // Check if this happens to be the lazy alignment of our element type, in | 20459 | // Check if this happens to be the lazy alignment of our element type, in |
| 20454 | // which case we can make this 0 without resolving it. | 20460 | // which case we can make this 0 without resolving it. |
| 20455 | switch (zcu.intern_pool.indexToKey(val.toIntern())) { | 20461 | switch (zcu.intern_pool.indexToKey(val.toIntern())) { |
| ... | @@ -20472,18 +20478,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -20472,18 +20478,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20472 | const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: { | 20478 | const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 20473 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 20479 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 20474 | extra_i += 1; | 20480 | extra_i += 1; |
| 20475 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{ | 20481 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{ .simple = .type }); |
| 20476 | .needed_comptime_reason = "pointer bit-offset must be comptime-known", | | |
| 20477 | }); | | |
| 20478 | break :blk @intCast(bit_offset); | 20482 | break :blk @intCast(bit_offset); |
| 20479 | } else 0; | 20483 | } else 0; |
| 20480 | | 20484 | |
| 20481 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 20485 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 20482 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); | 20486 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 20483 | extra_i += 1; | 20487 | extra_i += 1; |
| 20484 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{ | 20488 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{ .simple = .type }); |
| 20485 | .needed_comptime_reason = "pointer host size must be comptime-known", | | |
| 20486 | }); | | |
| 20487 | break :blk @intCast(host_size); | 20489 | break :blk @intCast(host_size); |
| 20488 | } else 0; | 20490 | } else 0; |
| 20489 | | 20491 | |
| ... | @@ -20671,9 +20673,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -20671,9 +20673,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 20671 | if (union_ty.zigTypeTag(pt.zcu) != .@"union") { | 20673 | if (union_ty.zigTypeTag(pt.zcu) != .@"union") { |
| 20672 | return sema.fail(block, ty_src, "expected union type, found '{}'", .{union_ty.fmt(pt)}); | 20674 | return sema.fail(block, ty_src, "expected union type, found '{}'", .{union_ty.fmt(pt)}); |
| 20673 | } | 20675 | } |
| 20674 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ | 20676 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .union_field_name }); |
| 20675 | .needed_comptime_reason = "name of field being initialized must be comptime-known", | | |
| 20676 | }); | | |
| 20677 | const init = try sema.resolveInst(extra.init); | 20677 | const init = try sema.resolveInst(extra.init); |
| 20678 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); | 20678 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); |
| 20679 | } | 20679 | } |
| ... | @@ -20800,9 +20800,7 @@ fn zirStructInit( | ... | @@ -20800,9 +20800,7 @@ fn zirStructInit( |
| 20800 | try resolved_ty.resolveStructFieldInits(pt); | 20800 | try resolved_ty.resolveStructFieldInits(pt); |
| 20801 | if (try resolved_ty.structFieldValueComptime(pt, field_index)) |default_value| { | 20801 | if (try resolved_ty.structFieldValueComptime(pt, field_index)) |default_value| { |
| 20802 | const init_val = (try sema.resolveValue(field_inits[field_index])) orelse { | 20802 | const init_val = (try sema.resolveValue(field_inits[field_index])) orelse { |
| 20803 | return sema.failWithNeededComptime(block, field_src, .{ | 20803 | return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field }); |
| 20804 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | | |
| 20805 | }); | | |
| 20806 | }; | 20804 | }; |
| 20807 | | 20805 | |
| 20808 | if (!init_val.eql(default_value, resolved_ty.fieldType(field_index, zcu), zcu)) { | 20806 | if (!init_val.eql(default_value, resolved_ty.fieldType(field_index, zcu), zcu)) { |
| ... | @@ -20862,9 +20860,10 @@ fn zirStructInit( | ... | @@ -20862,9 +20860,10 @@ fn zirStructInit( |
| 20862 | } | 20860 | } |
| 20863 | | 20861 | |
| 20864 | if (try resolved_ty.comptimeOnlySema(pt)) { | 20862 | if (try resolved_ty.comptimeOnlySema(pt)) { |
| 20865 | return sema.failWithNeededComptime(block, field_src, .{ | 20863 | return sema.failWithNeededComptime(block, field_src, .{ .comptime_only = .{ |
| 20866 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", | 20864 | .ty = resolved_ty, |
| 20867 | }); | 20865 | .msg = .union_init, |
| | 20866 | } }); |
| 20868 | } | 20867 | } |
| 20869 | | 20868 | |
| 20870 | try sema.validateRuntimeValue(block, field_src, init_inst); | 20869 | try sema.validateRuntimeValue(block, field_src, init_inst); |
| ... | @@ -21003,9 +21002,10 @@ fn finishStructInit( | ... | @@ -21003,9 +21002,10 @@ fn finishStructInit( |
| 21003 | return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{ | 21002 | return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{ |
| 21004 | .init_node_offset = init_src.offset.node_offset.x, | 21003 | .init_node_offset = init_src.offset.node_offset.x, |
| 21005 | .elem_index = @intCast(runtime_index), | 21004 | .elem_index = @intCast(runtime_index), |
| 21006 | } }), .{ | 21005 | } }), .{ .comptime_only = .{ |
| 21007 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 21006 | .ty = struct_ty, |
| 21008 | }); | 21007 | .msg = .struct_init, |
| | 21008 | } }); |
| 21009 | } | 21009 | } |
| 21010 | | 21010 | |
| 21011 | for (field_inits) |field_init| { | 21011 | for (field_inits) |field_init| { |
| ... | @@ -21315,11 +21315,7 @@ fn zirArrayInit( | ... | @@ -21315,11 +21315,7 @@ fn zirArrayInit( |
| 21315 | if (array_ty.structFieldIsComptime(i, zcu)) | 21315 | if (array_ty.structFieldIsComptime(i, zcu)) |
| 21316 | try array_ty.resolveStructFieldInits(pt); | 21316 | try array_ty.resolveStructFieldInits(pt); |
| 21317 | if (try array_ty.structFieldValueComptime(pt, i)) |field_val| { | 21317 | if (try array_ty.structFieldValueComptime(pt, i)) |field_val| { |
| 21318 | const init_val = try sema.resolveValue(dest.*) orelse { | 21318 | const init_val = try sema.resolveConstValue(block, elem_src, dest.*, .{ .simple = .stored_to_comptime_field }); |
| 21319 | return sema.failWithNeededComptime(block, elem_src, .{ | | |
| 21320 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | | |
| 21321 | }); | | |
| 21322 | }; | | |
| 21323 | if (!field_val.eql(init_val, elem_ty, zcu)) { | 21319 | if (!field_val.eql(init_val, elem_ty, zcu)) { |
| 21324 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); | 21320 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); |
| 21325 | } | 21321 | } |
| ... | @@ -21508,9 +21504,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -21508,9 +21504,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21508 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 21504 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21509 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 21505 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 21510 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 21506 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 21511 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ | 21507 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ .simple = .field_name }); |
| 21512 | .needed_comptime_reason = "field name must be comptime-known", | | |
| 21513 | }); | | |
| 21514 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); | 21508 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 21515 | } | 21509 | } |
| 21516 | | 21510 | |
| ... | @@ -21890,9 +21884,7 @@ fn zirReify( | ... | @@ -21890,9 +21884,7 @@ fn zirReify( |
| 21890 | const type_info_ty = try sema.getBuiltinType("Type"); | 21884 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21891 | const uncasted_operand = try sema.resolveInst(extra.operand); | 21885 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 21892 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 21886 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21893 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ | 21887 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ .simple = .operand_Type }); |
| 21894 | .needed_comptime_reason = "operand to @Type must be comptime-known", | | |
| 21895 | }); | | |
| 21896 | const union_val = ip.indexToKey(val.toIntern()).un; | 21888 | const union_val = ip.indexToKey(val.toIntern()).un; |
| 21897 | if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) { | 21889 | if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) { |
| 21898 | return sema.failWithUseOfUndef(block, operand_src); | 21890 | return sema.failWithUseOfUndef(block, operand_src); |
| ... | @@ -22136,9 +22128,7 @@ fn zirReify( | ... | @@ -22136,9 +22128,7 @@ fn zirReify( |
| 22136 | const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse | 22128 | const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse |
| 22137 | return Air.internedToRef(Type.anyerror.toIntern()); | 22129 | return Air.internedToRef(Type.anyerror.toIntern()); |
| 22138 | | 22130 | |
| 22139 | const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{ | 22131 | const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{ .simple = .error_set_contents }); |
| 22140 | .needed_comptime_reason = "error set contents must be comptime-known", | | |
| 22141 | }); | | |
| 22142 | | 22132 | |
| 22143 | const len = try sema.usizeCast(block, src, names_val.typeOf(zcu).arrayLen(zcu)); | 22133 | const len = try sema.usizeCast(block, src, names_val.typeOf(zcu).arrayLen(zcu)); |
| 22144 | var names: InferredErrorSet.NameMap = .{}; | 22134 | var names: InferredErrorSet.NameMap = .{}; |
| ... | @@ -22151,9 +22141,7 @@ fn zirReify( | ... | @@ -22151,9 +22141,7 @@ fn zirReify( |
| 22151 | try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), | 22141 | try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), |
| 22152 | ).?); | 22142 | ).?); |
| 22153 | | 22143 | |
| 22154 | const name = try sema.sliceToIpString(block, src, name_val, .{ | 22144 | const name = try sema.sliceToIpString(block, src, name_val, .{ .simple = .error_set_contents }); |
| 22155 | .needed_comptime_reason = "error set contents must be comptime-known", | | |
| 22156 | }); | | |
| 22157 | _ = try pt.getErrorValue(name); | 22145 | _ = try pt.getErrorValue(name); |
| 22158 | const gop = names.getOrPutAssumeCapacity(name); | 22146 | const gop = names.getOrPutAssumeCapacity(name); |
| 22159 | if (gop.found_existing) { | 22147 | if (gop.found_existing) { |
| ... | @@ -22200,9 +22188,7 @@ fn zirReify( | ... | @@ -22200,9 +22188,7 @@ fn zirReify( |
| 22200 | return sema.fail(block, src, "non-packed struct does not support backing integer type", .{}); | 22188 | return sema.fail(block, src, "non-packed struct does not support backing integer type", .{}); |
| 22201 | } | 22189 | } |
| 22202 | | 22190 | |
| 22203 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ | 22191 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ .simple = .struct_fields }); |
| 22204 | .needed_comptime_reason = "struct fields must be comptime-known", | | |
| 22205 | }); | | |
| 22206 | | 22192 | |
| 22207 | if (is_tuple_val.toBool()) { | 22193 | if (is_tuple_val.toBool()) { |
| 22208 | switch (layout) { | 22194 | switch (layout) { |
| ... | @@ -22238,9 +22224,7 @@ fn zirReify( | ... | @@ -22238,9 +22224,7 @@ fn zirReify( |
| 22238 | return sema.fail(block, src, "reified enums must have no decls", .{}); | 22224 | return sema.fail(block, src, "reified enums must have no decls", .{}); |
| 22239 | } | 22225 | } |
| 22240 | | 22226 | |
| 22241 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ | 22227 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ .simple = .enum_fields }); |
| 22242 | .needed_comptime_reason = "enum fields must be comptime-known", | | |
| 22243 | }); | | |
| 22244 | | 22228 | |
| 22245 | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy); | 22229 | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy); |
| 22246 | }, | 22230 | }, |
| ... | @@ -22311,9 +22295,7 @@ fn zirReify( | ... | @@ -22311,9 +22295,7 @@ fn zirReify( |
| 22311 | } | 22295 | } |
| 22312 | const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val); | 22296 | const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val); |
| 22313 | | 22297 | |
| 22314 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ | 22298 | const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{ .simple = .union_fields }); |
| 22315 | .needed_comptime_reason = "union fields must be comptime-known", | | |
| 22316 | }); | | |
| 22317 | | 22299 | |
| 22318 | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy); | 22300 | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy); |
| 22319 | }, | 22301 | }, |
| ... | @@ -22354,9 +22336,7 @@ fn zirReify( | ... | @@ -22354,9 +22336,7 @@ fn zirReify( |
| 22354 | const return_type = return_type_val.optionalValue(zcu) orelse | 22336 | const return_type = return_type_val.optionalValue(zcu) orelse |
| 22355 | return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{}); | 22337 | return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{}); |
| 22356 | | 22338 | |
| 22357 | const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{ | 22339 | const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{ .simple = .function_parameters }); |
| 22358 | .needed_comptime_reason = "function parameters must be comptime-known", | | |
| 22359 | }); | | |
| 22360 | | 22340 | |
| 22361 | const args_len = try sema.usizeCast(block, src, params_val.typeOf(zcu).arrayLen(zcu)); | 22341 | const args_len = try sema.usizeCast(block, src, params_val.typeOf(zcu).arrayLen(zcu)); |
| 22362 | const param_types = try sema.arena.alloc(InternPool.Index, args_len); | 22342 | const param_types = try sema.arena.alloc(InternPool.Index, args_len); |
| ... | @@ -22444,9 +22424,7 @@ fn reifyEnum( | ... | @@ -22444,9 +22424,7 @@ fn reifyEnum( |
| 22444 | const field_name_val = try field_info.fieldValue(pt, 0); | 22424 | const field_name_val = try field_info.fieldValue(pt, 0); |
| 22445 | const field_value_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 1)); | 22425 | const field_value_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 1)); |
| 22446 | | 22426 | |
| 22447 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ | 22427 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ .simple = .enum_field_name }); |
| 22448 | .needed_comptime_reason = "enum field name must be comptime-known", | | |
| 22449 | }); | | |
| 22450 | | 22428 | |
| 22451 | std.hash.autoHash(&hasher, .{ | 22429 | std.hash.autoHash(&hasher, .{ |
| 22452 | field_name, | 22430 | field_name, |
| ... | @@ -22591,9 +22569,7 @@ fn reifyUnion( | ... | @@ -22591,9 +22569,7 @@ fn reifyUnion( |
| 22591 | const field_type_val = try field_info.fieldValue(pt, 1); | 22569 | const field_type_val = try field_info.fieldValue(pt, 1); |
| 22592 | const field_align_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 2)); | 22570 | const field_align_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 2)); |
| 22593 | | 22571 | |
| 22594 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ | 22572 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ .simple = .union_field_name }); |
| 22595 | .needed_comptime_reason = "union field name must be comptime-known", | | |
| 22596 | }); | | |
| 22597 | | 22573 | |
| 22598 | std.hash.autoHash(&hasher, .{ | 22574 | std.hash.autoHash(&hasher, .{ |
| 22599 | field_name, | 22575 | field_name, |
| ... | @@ -22835,9 +22811,7 @@ fn reifyTuple( | ... | @@ -22835,9 +22811,7 @@ fn reifyTuple( |
| 22835 | const field_is_comptime_val = try field_info.fieldValue(pt, 3); | 22811 | const field_is_comptime_val = try field_info.fieldValue(pt, 3); |
| 22836 | const field_alignment_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 4)); | 22812 | const field_alignment_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 4)); |
| 22837 | | 22813 | |
| 22838 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ | 22814 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ .simple = .tuple_field_name }); |
| 22839 | .needed_comptime_reason = "tuple field name must be comptime-known", | | |
| 22840 | }); | | |
| 22841 | const field_type = field_type_val.toType(); | 22815 | const field_type = field_type_val.toType(); |
| 22842 | const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: { | 22816 | const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: { |
| 22843 | const ptr_ty = try pt.singleConstPtrType(field_type_val.toType()); | 22817 | const ptr_ty = try pt.singleConstPtrType(field_type_val.toType()); |
| ... | @@ -22845,7 +22819,7 @@ fn reifyTuple( | ... | @@ -22845,7 +22819,7 @@ fn reifyTuple( |
| 22845 | const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime( | 22819 | const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime( |
| 22846 | block, | 22820 | block, |
| 22847 | src, | 22821 | src, |
| 22848 | .{ .needed_comptime_reason = "tuple field default value must be comptime-known" }, | 22822 | .{ .simple = .tuple_field_default_value }, |
| 22849 | ); | 22823 | ); |
| 22850 | // Resolve the value so that lazy values do not create distinct types. | 22824 | // Resolve the value so that lazy values do not create distinct types. |
| 22851 | break :d (try sema.resolveLazyValue(val)).toIntern(); | 22825 | break :d (try sema.resolveLazyValue(val)).toIntern(); |
| ... | @@ -22951,9 +22925,7 @@ fn reifyStruct( | ... | @@ -22951,9 +22925,7 @@ fn reifyStruct( |
| 22951 | const field_is_comptime_val = try field_info.fieldValue(pt, 3); | 22925 | const field_is_comptime_val = try field_info.fieldValue(pt, 3); |
| 22952 | const field_alignment_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 4)); | 22926 | const field_alignment_val = try sema.resolveLazyValue(try field_info.fieldValue(pt, 4)); |
| 22953 | | 22927 | |
| 22954 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ | 22928 | const field_name = try sema.sliceToIpString(block, src, field_name_val, .{ .simple = .struct_field_name }); |
| 22955 | .needed_comptime_reason = "struct field name must be comptime-known", | | |
| 22956 | }); | | |
| 22957 | const field_is_comptime = field_is_comptime_val.toBool(); | 22929 | const field_is_comptime = field_is_comptime_val.toBool(); |
| 22958 | const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: { | 22930 | const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: { |
| 22959 | const ptr_ty = try pt.singleConstPtrType(field_type_val.toType()); | 22931 | const ptr_ty = try pt.singleConstPtrType(field_type_val.toType()); |
| ... | @@ -22961,7 +22933,7 @@ fn reifyStruct( | ... | @@ -22961,7 +22933,7 @@ fn reifyStruct( |
| 22961 | const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime( | 22933 | const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime( |
| 22962 | block, | 22934 | block, |
| 22963 | src, | 22935 | src, |
| 22964 | .{ .needed_comptime_reason = "struct field default value must be comptime-known" }, | 22936 | .{ .simple = .struct_field_default_value }, |
| 22965 | ); | 22937 | ); |
| 22966 | // Resolve the value so that lazy values do not create distinct types. | 22938 | // Resolve the value so that lazy values do not create distinct types. |
| 22967 | break :d (try sema.resolveLazyValue(val)).toIntern(); | 22939 | break :d (try sema.resolveLazyValue(val)).toIntern(); |
| ... | @@ -23285,9 +23257,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -23285,9 +23257,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 23285 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate); | 23257 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate); |
| 23286 | return Air.internedToRef(result_val.toIntern()); | 23258 | return Air.internedToRef(result_val.toIntern()); |
| 23287 | } else if (dest_scalar_ty.zigTypeTag(zcu) == .comptime_int) { | 23259 | } else if (dest_scalar_ty.zigTypeTag(zcu) == .comptime_int) { |
| 23288 | return sema.failWithNeededComptime(block, operand_src, .{ | 23260 | return sema.failWithNeededComptime(block, operand_src, .{ .simple = .casted_to_comptime_int }); |
| 23289 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", | | |
| 23290 | }); | | |
| 23291 | } | 23261 | } |
| 23292 | | 23262 | |
| 23293 | try sema.requireRuntimeBlock(block, src, operand_src); | 23263 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -23368,9 +23338,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -23368,9 +23338,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 23368 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema); | 23338 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema); |
| 23369 | return Air.internedToRef(result_val.toIntern()); | 23339 | return Air.internedToRef(result_val.toIntern()); |
| 23370 | } else if (dest_scalar_ty.zigTypeTag(zcu) == .comptime_float) { | 23340 | } else if (dest_scalar_ty.zigTypeTag(zcu) == .comptime_float) { |
| 23371 | return sema.failWithNeededComptime(block, operand_src, .{ | 23341 | return sema.failWithNeededComptime(block, operand_src, .{ .simple = .casted_to_comptime_float }); |
| 23372 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", | | |
| 23373 | }); | | |
| 23374 | } | 23342 | } |
| 23375 | | 23343 | |
| 23376 | try sema.requireRuntimeBlock(block, src, operand_src); | 23344 | try sema.requireRuntimeBlock(block, src, operand_src); |
| ... | @@ -24394,9 +24362,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -24394,9 +24362,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 24394 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24362 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24395 | | 24363 | |
| 24396 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 24364 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| 24397 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ | 24365 | const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ .simple = .field_name }); |
| 24398 | .needed_comptime_reason = "name of field must be comptime-known", | | |
| 24399 | }); | | |
| 24400 | | 24366 | |
| 24401 | const pt = sema.pt; | 24367 | const pt = sema.pt; |
| 24402 | const zcu = pt.zcu; | 24368 | const zcu = pt.zcu; |
| ... | @@ -24850,31 +24816,21 @@ fn resolveExportOptions( | ... | @@ -24850,31 +24816,21 @@ fn resolveExportOptions( |
| 24850 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 24816 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24851 | | 24817 | |
| 24852 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); | 24818 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); |
| 24853 | const name = try sema.toConstString(block, name_src, name_operand, .{ | 24819 | const name = try sema.toConstString(block, name_src, name_operand, .{ .simple = .export_options }); |
| 24854 | .needed_comptime_reason = "name of exported value must be comptime-known", | | |
| 24855 | }); | | |
| 24856 | | 24820 | |
| 24857 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); | 24821 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); |
| 24858 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ | 24822 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ .simple = .export_options }); |
| 24859 | .needed_comptime_reason = "linkage of exported value must be comptime-known", | | |
| 24860 | }); | | |
| 24861 | const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); | 24823 | const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 24862 | | 24824 | |
| 24863 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src); | 24825 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src); |
| 24864 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ | 24826 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ .simple = .export_options }); |
| 24865 | .needed_comptime_reason = "linksection of exported value must be comptime-known", | | |
| 24866 | }); | | |
| 24867 | const section = if (section_opt_val.optionalValue(zcu)) |section_val| | 24827 | const section = if (section_opt_val.optionalValue(zcu)) |section_val| |
| 24868 | try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{ | 24828 | try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{ .simple = .export_options }) |
| 24869 | .needed_comptime_reason = "linksection of exported value must be comptime-known", | | |
| 24870 | }) | | |
| 24871 | else | 24829 | else |
| 24872 | null; | 24830 | null; |
| 24873 | | 24831 | |
| 24874 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "visibility", .no_embedded_nulls), visibility_src); | 24832 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "visibility", .no_embedded_nulls), visibility_src); |
| 24875 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ | 24833 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ .simple = .export_options }); |
| 24876 | .needed_comptime_reason = "visibility of exported value must be comptime-known", | | |
| 24877 | }); | | |
| 24878 | const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val); | 24834 | const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| 24879 | | 24835 | |
| 24880 | if (name.len < 1) { | 24836 | if (name.len < 1) { |
| ... | @@ -24901,7 +24857,7 @@ fn resolveBuiltinEnum( | ... | @@ -24901,7 +24857,7 @@ fn resolveBuiltinEnum( |
| 24901 | src: LazySrcLoc, | 24857 | src: LazySrcLoc, |
| 24902 | zir_ref: Zir.Inst.Ref, | 24858 | zir_ref: Zir.Inst.Ref, |
| 24903 | comptime name: []const u8, | 24859 | comptime name: []const u8, |
| 24904 | reason: NeededComptimeReason, | 24860 | reason: ComptimeReason, |
| 24905 | ) CompileError!@field(std.builtin, name) { | 24861 | ) CompileError!@field(std.builtin, name) { |
| 24906 | const pt = sema.pt; | 24862 | const pt = sema.pt; |
| 24907 | const ty = try sema.getBuiltinType(name); | 24863 | const ty = try sema.getBuiltinType(name); |
| ... | @@ -24916,7 +24872,7 @@ fn resolveAtomicOrder( | ... | @@ -24916,7 +24872,7 @@ fn resolveAtomicOrder( |
| 24916 | block: *Block, | 24872 | block: *Block, |
| 24917 | src: LazySrcLoc, | 24873 | src: LazySrcLoc, |
| 24918 | zir_ref: Zir.Inst.Ref, | 24874 | zir_ref: Zir.Inst.Ref, |
| 24919 | reason: NeededComptimeReason, | 24875 | reason: ComptimeReason, |
| 24920 | ) CompileError!std.builtin.AtomicOrder { | 24876 | ) CompileError!std.builtin.AtomicOrder { |
| 24921 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); | 24877 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason); |
| 24922 | } | 24878 | } |
| ... | @@ -24927,9 +24883,7 @@ fn resolveAtomicRmwOp( | ... | @@ -24927,9 +24883,7 @@ fn resolveAtomicRmwOp( |
| 24927 | src: LazySrcLoc, | 24883 | src: LazySrcLoc, |
| 24928 | zir_ref: Zir.Inst.Ref, | 24884 | zir_ref: Zir.Inst.Ref, |
| 24929 | ) CompileError!std.builtin.AtomicRmwOp { | 24885 | ) CompileError!std.builtin.AtomicRmwOp { |
| 24930 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{ | 24886 | return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{ .simple = .operand_atomicRmw_operation }); |
| 24931 | .needed_comptime_reason = "@atomicRmW operation must be comptime-known", | | |
| 24932 | }); | | |
| 24933 | } | 24887 | } |
| 24934 | | 24888 | |
| 24935 | fn zirCmpxchg( | 24889 | fn zirCmpxchg( |
| ... | @@ -24967,12 +24921,8 @@ fn zirCmpxchg( | ... | @@ -24967,12 +24921,8 @@ fn zirCmpxchg( |
| 24967 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 24921 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 24968 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 24922 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 24969 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); | 24923 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); |
| 24970 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{ | 24924 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{ .simple = .atomic_order }); |
| 24971 | .needed_comptime_reason = "atomic order of cmpxchg success must be comptime-known", | 24925 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{ .simple = .atomic_order }); |
| 24972 | }); | | |
| 24973 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{ | | |
| 24974 | .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known", | | |
| 24975 | }); | | |
| 24976 | | 24926 | |
| 24977 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.monotonic)) { | 24927 | if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.monotonic)) { |
| 24978 | return sema.fail(block, success_order_src, "success atomic ordering must be monotonic or stricter", .{}); | 24928 | return sema.fail(block, success_order_src, "success atomic ordering must be monotonic or stricter", .{}); |
| ... | @@ -25113,9 +25063,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -25113,9 +25063,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 25113 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25063 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25114 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); | 25064 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25115 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); | 25065 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25116 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ | 25066 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ .simple = .operand_reduce_operation }); |
| 25117 | .needed_comptime_reason = "@reduce operation must be comptime-known", | | |
| 25118 | }); | | |
| 25119 | const operand = try sema.resolveInst(extra.rhs); | 25067 | const operand = try sema.resolveInst(extra.rhs); |
| 25120 | const operand_ty = sema.typeOf(operand); | 25068 | const operand_ty = sema.typeOf(operand); |
| 25121 | const pt = sema.pt; | 25069 | const pt = sema.pt; |
| ... | @@ -25204,9 +25152,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -25204,9 +25152,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 25204 | .child = .i32_type, | 25152 | .child = .i32_type, |
| 25205 | }); | 25153 | }); |
| 25206 | mask = try sema.coerce(block, mask_ty, mask, mask_src); | 25154 | mask = try sema.coerce(block, mask_ty, mask, mask_src); |
| 25207 | const mask_val = try sema.resolveConstValue(block, mask_src, mask, .{ | 25155 | const mask_val = try sema.resolveConstValue(block, mask_src, mask, .{ .simple = .operand_shuffle_mask }); |
| 25208 | .needed_comptime_reason = "shuffle mask must be comptime-known", | | |
| 25209 | }); | | |
| 25210 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); | 25156 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); |
| 25211 | } | 25157 | } |
| 25212 | | 25158 | |
| ... | @@ -25474,9 +25420,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -25474,9 +25420,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 25474 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 25420 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 25475 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 25421 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 25476 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); | 25422 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); |
| 25477 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ | 25423 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ .simple = .atomic_order }); |
| 25478 | .needed_comptime_reason = "atomic order of @atomicLoad must be comptime-known", | | |
| 25479 | }); | | |
| 25480 | | 25424 | |
| 25481 | switch (order) { | 25425 | switch (order) { |
| 25482 | .release, .acq_rel => { | 25426 | .release, .acq_rel => { |
| ... | @@ -25542,9 +25486,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -25542,9 +25486,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25542 | }, | 25486 | }, |
| 25543 | else => {}, | 25487 | else => {}, |
| 25544 | } | 25488 | } |
| 25545 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ | 25489 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ .simple = .atomic_order }); |
| 25546 | .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known", | | |
| 25547 | }); | | |
| 25548 | | 25490 | |
| 25549 | if (order == .unordered) { | 25491 | if (order == .unordered) { |
| 25550 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be unordered", .{}); | 25492 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be unordered", .{}); |
| ... | @@ -25611,9 +25553,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -25611,9 +25553,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25611 | const elem_ty = sema.typeOf(operand); | 25553 | const elem_ty = sema.typeOf(operand); |
| 25612 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 25554 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 25613 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 25555 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 25614 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ | 25556 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ .simple = .atomic_order }); |
| 25615 | .needed_comptime_reason = "atomic order of @atomicStore must be comptime-known", | | |
| 25616 | }); | | |
| 25617 | | 25557 | |
| 25618 | const air_tag: Air.Inst.Tag = switch (order) { | 25558 | const air_tag: Air.Inst.Tag = switch (order) { |
| 25619 | .acquire, .acq_rel => { | 25559 | .acquire, .acq_rel => { |
| ... | @@ -25716,14 +25656,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -25716,14 +25656,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25716 | const modifier_ty = try sema.getBuiltinType("CallModifier"); | 25656 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 25717 | const air_ref = try sema.resolveInst(extra.modifier); | 25657 | const air_ref = try sema.resolveInst(extra.modifier); |
| 25718 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); | 25658 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 25719 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ | 25659 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ .simple = .call_modifier }); |
| 25720 | .needed_comptime_reason = "call modifier must be comptime-known", | | |
| 25721 | }); | | |
| 25722 | var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val); | 25660 | var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val); |
| 25723 | switch (modifier) { | 25661 | switch (modifier) { |
| 25724 | // These can be upgraded to comptime or nosuspend calls. | 25662 | // These can be upgraded to comptime or nosuspend calls. |
| 25725 | .auto, .never_tail, .no_async => { | 25663 | .auto, .never_tail, .no_async => { |
| 25726 | if (block.is_comptime) { | 25664 | if (block.isComptime()) { |
| 25727 | if (modifier == .never_tail) { | 25665 | if (modifier == .never_tail) { |
| 25728 | return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{}); | 25666 | return sema.fail(block, modifier_src, "unable to perform 'never_tail' call at compile-time", .{}); |
| 25729 | } | 25667 | } |
| ... | @@ -25738,12 +25676,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -25738,12 +25676,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25738 | return sema.fail(block, func_src, "modifier '{s}' requires a comptime-known function", .{@tagName(modifier)}); | 25676 | return sema.fail(block, func_src, "modifier '{s}' requires a comptime-known function", .{@tagName(modifier)}); |
| 25739 | }; | 25677 | }; |
| 25740 | | 25678 | |
| 25741 | if (block.is_comptime) { | 25679 | if (block.isComptime()) { |
| 25742 | modifier = .compile_time; | 25680 | modifier = .compile_time; |
| 25743 | } | 25681 | } |
| 25744 | }, | 25682 | }, |
| 25745 | .always_tail => { | 25683 | .always_tail => { |
| 25746 | if (block.is_comptime) { | 25684 | if (block.isComptime()) { |
| 25747 | modifier = .compile_time; | 25685 | modifier = .compile_time; |
| 25748 | } | 25686 | } |
| 25749 | }, | 25687 | }, |
| ... | @@ -25751,12 +25689,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -25751,12 +25689,12 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 25751 | if (extra.flags.is_nosuspend) { | 25689 | if (extra.flags.is_nosuspend) { |
| 25752 | return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{}); | 25690 | return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used inside nosuspend block", .{}); |
| 25753 | } | 25691 | } |
| 25754 | if (block.is_comptime) { | 25692 | if (block.isComptime()) { |
| 25755 | return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used in combination with comptime function call", .{}); | 25693 | return sema.fail(block, modifier_src, "modifier 'async_kw' cannot be used in combination with comptime function call", .{}); |
| 25756 | } | 25694 | } |
| 25757 | }, | 25695 | }, |
| 25758 | .never_inline => { | 25696 | .never_inline => { |
| 25759 | if (block.is_comptime) { | 25697 | if (block.isComptime()) { |
| 25760 | return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{}); | 25698 | return sema.fail(block, modifier_src, "unable to perform 'never_inline' call at compile-time", .{}); |
| 25761 | } | 25699 | } |
| 25762 | }, | 25700 | }, |
| ... | @@ -25820,9 +25758,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins | ... | @@ -25820,9 +25758,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins |
| 25820 | } | 25758 | } |
| 25821 | try parent_ty.resolveLayout(pt); | 25759 | try parent_ty.resolveLayout(pt); |
| 25822 | | 25760 | |
| 25823 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 25761 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name }); |
| 25824 | .needed_comptime_reason = "field name must be comptime-known", | | |
| 25825 | }); | | |
| 25826 | const field_index = switch (parent_ty.zigTypeTag(zcu)) { | 25762 | const field_index = switch (parent_ty.zigTypeTag(zcu)) { |
| 25827 | .@"struct" => blk: { | 25763 | .@"struct" => blk: { |
| 25828 | if (parent_ty.isTuple(zcu)) { | 25764 | if (parent_ty.isTuple(zcu)) { |
| ... | @@ -26680,9 +26616,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26680,9 +26616,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26680 | extra_index += body.len; | 26616 | extra_index += body.len; |
| 26681 | | 26617 | |
| 26682 | const cc_ty = try sema.getBuiltinType("CallingConvention"); | 26618 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26683 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ | 26619 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{ .simple = .@"callconv" }); |
| 26684 | .needed_comptime_reason = "calling convention must be comptime-known", | | |
| 26685 | }); | | |
| 26686 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, val); | 26620 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, val); |
| 26687 | } else if (extra.data.bits.has_cc_ref) blk: { | 26621 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 26688 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 26622 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| ... | @@ -26690,9 +26624,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26690,9 +26624,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26690 | const cc_ty = try sema.getBuiltinType("CallingConvention"); | 26624 | const cc_ty = try sema.getBuiltinType("CallingConvention"); |
| 26691 | const uncoerced_cc = try sema.resolveInst(cc_ref); | 26625 | const uncoerced_cc = try sema.resolveInst(cc_ref); |
| 26692 | const coerced_cc = try sema.coerce(block, cc_ty, uncoerced_cc, cc_src); | 26626 | const coerced_cc = try sema.coerce(block, cc_ty, uncoerced_cc, cc_src); |
| 26693 | const cc_val = try sema.resolveConstDefinedValue(block, cc_src, coerced_cc, .{ | 26627 | const cc_val = try sema.resolveConstDefinedValue(block, cc_src, coerced_cc, .{ .simple = .@"callconv" }); |
| 26694 | .needed_comptime_reason = "calling convention must be comptime-known", | | |
| 26695 | }); | | |
| 26696 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, cc_val); | 26628 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, cc_val); |
| 26697 | } else cc: { | 26629 | } else cc: { |
| 26698 | if (has_body) { | 26630 | if (has_body) { |
| ... | @@ -26730,9 +26662,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26730,9 +26662,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26730 | const body = sema.code.bodySlice(extra_index, body_len); | 26662 | const body = sema.code.bodySlice(extra_index, body_len); |
| 26731 | extra_index += body.len; | 26663 | extra_index += body.len; |
| 26732 | | 26664 | |
| 26733 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ | 26665 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{ .simple = .function_ret_ty }); |
| 26734 | .needed_comptime_reason = "return type must be comptime-known", | | |
| 26735 | }); | | |
| 26736 | const ty = val.toType(); | 26666 | const ty = val.toType(); |
| 26737 | break :blk ty; | 26667 | break :blk ty; |
| 26738 | } else if (extra.data.bits.has_ret_ty_ref) blk: { | 26668 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| ... | @@ -26742,9 +26672,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -26742,9 +26672,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 26742 | error.GenericPoison => break :blk Type.generic_poison, | 26672 | error.GenericPoison => break :blk Type.generic_poison, |
| 26743 | else => |e| return e, | 26673 | else => |e| return e, |
| 26744 | }; | 26674 | }; |
| 26745 | const ret_ty_val = sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ | 26675 | const ret_ty_val = sema.resolveConstDefinedValue(block, ret_src, ret_ty_air_ref, .{ .simple = .function_ret_ty }) catch |err| switch (err) { |
| 26746 | .needed_comptime_reason = "return type must be comptime-known", | | |
| 26747 | }) catch |err| switch (err) { | | |
| 26748 | error.GenericPoison => break :blk Type.generic_poison, | 26676 | error.GenericPoison => break :blk Type.generic_poison, |
| 26749 | else => |e| return e, | 26677 | else => |e| return e, |
| 26750 | }; | 26678 | }; |
| ... | @@ -26790,9 +26718,7 @@ fn zirCUndef( | ... | @@ -26790,9 +26718,7 @@ fn zirCUndef( |
| 26790 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26718 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26791 | const src = block.builtinCallArgSrc(extra.node, 0); | 26719 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26792 | | 26720 | |
| 26793 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26721 | const name = try sema.resolveConstString(block, src, extra.operand, .{ .simple = .operand_cUndef_macro_name }); |
| 26794 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | | |
| 26795 | }); | | |
| 26796 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); | 26722 | try block.c_import_buf.?.writer().print("#undef {s}\n", .{name}); |
| 26797 | return .void_value; | 26723 | return .void_value; |
| 26798 | } | 26724 | } |
| ... | @@ -26805,9 +26731,7 @@ fn zirCInclude( | ... | @@ -26805,9 +26731,7 @@ fn zirCInclude( |
| 26805 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26731 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26806 | const src = block.builtinCallArgSrc(extra.node, 0); | 26732 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26807 | | 26733 | |
| 26808 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26734 | const name = try sema.resolveConstString(block, src, extra.operand, .{ .simple = .operand_cInclude_file_name }); |
| 26809 | .needed_comptime_reason = "path being included must be comptime-known", | | |
| 26810 | }); | | |
| 26811 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); | 26735 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); |
| 26812 | return .void_value; | 26736 | return .void_value; |
| 26813 | } | 26737 | } |
| ... | @@ -26823,14 +26747,10 @@ fn zirCDefine( | ... | @@ -26823,14 +26747,10 @@ fn zirCDefine( |
| 26823 | const name_src = block.builtinCallArgSrc(extra.node, 0); | 26747 | const name_src = block.builtinCallArgSrc(extra.node, 0); |
| 26824 | const val_src = block.builtinCallArgSrc(extra.node, 1); | 26748 | const val_src = block.builtinCallArgSrc(extra.node, 1); |
| 26825 | | 26749 | |
| 26826 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ | 26750 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ .simple = .operand_cDefine_macro_name }); |
| 26827 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | | |
| 26828 | }); | | |
| 26829 | const rhs = try sema.resolveInst(extra.rhs); | 26751 | const rhs = try sema.resolveInst(extra.rhs); |
| 26830 | if (sema.typeOf(rhs).zigTypeTag(zcu) != .void) { | 26752 | if (sema.typeOf(rhs).zigTypeTag(zcu) != .void) { |
| 26831 | const value = try sema.resolveConstString(block, val_src, extra.rhs, .{ | 26753 | const value = try sema.resolveConstString(block, val_src, extra.rhs, .{ .simple = .operand_cDefine_macro_value }); |
| 26832 | .needed_comptime_reason = "value of macro being undefined must be comptime-known", | | |
| 26833 | }); | | |
| 26834 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); | 26754 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); |
| 26835 | } else { | 26755 | } else { |
| 26836 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); | 26756 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); |
| ... | @@ -26851,9 +26771,7 @@ fn zirWasmMemorySize( | ... | @@ -26851,9 +26771,7 @@ fn zirWasmMemorySize( |
| 26851 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26771 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 26852 | } | 26772 | } |
| 26853 | | 26773 | |
| 26854 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{ | 26774 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{ .simple = .wasm_memory_index })); |
| 26855 | .needed_comptime_reason = "wasm memory size index must be comptime-known", | | |
| 26856 | })); | | |
| 26857 | try sema.requireRuntimeBlock(block, builtin_src, null); | 26775 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 26858 | return block.addInst(.{ | 26776 | return block.addInst(.{ |
| 26859 | .tag = .wasm_memory_size, | 26777 | .tag = .wasm_memory_size, |
| ... | @@ -26878,9 +26796,7 @@ fn zirWasmMemoryGrow( | ... | @@ -26878,9 +26796,7 @@ fn zirWasmMemoryGrow( |
| 26878 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26796 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 26879 | } | 26797 | } |
| 26880 | | 26798 | |
| 26881 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ | 26799 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ .simple = .wasm_memory_index })); |
| 26882 | .needed_comptime_reason = "wasm memory size index must be comptime-known", | | |
| 26883 | })); | | |
| 26884 | const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src); | 26800 | const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src); |
| 26885 | | 26801 | |
| 26886 | try sema.requireRuntimeBlock(block, builtin_src, null); | 26802 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| ... | @@ -26911,19 +26827,13 @@ fn resolvePrefetchOptions( | ... | @@ -26911,19 +26827,13 @@ fn resolvePrefetchOptions( |
| 26911 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26827 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26912 | | 26828 | |
| 26913 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "rw", .no_embedded_nulls), rw_src); | 26829 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "rw", .no_embedded_nulls), rw_src); |
| 26914 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ | 26830 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ .simple = .prefetch_options }); |
| 26915 | .needed_comptime_reason = "prefetch read/write must be comptime-known", | | |
| 26916 | }); | | |
| 26917 | | 26831 | |
| 26918 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "locality", .no_embedded_nulls), locality_src); | 26832 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "locality", .no_embedded_nulls), locality_src); |
| 26919 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ | 26833 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ .simple = .prefetch_options }); |
| 26920 | .needed_comptime_reason = "prefetch locality must be comptime-known", | | |
| 26921 | }); | | |
| 26922 | | 26834 | |
| 26923 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "cache", .no_embedded_nulls), cache_src); | 26835 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "cache", .no_embedded_nulls), cache_src); |
| 26924 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ | 26836 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ .simple = .prefetch_options }); |
| 26925 | .needed_comptime_reason = "prefetch cache must be comptime-known", | | |
| 26926 | }); | | |
| 26927 | | 26837 | |
| 26928 | return std.builtin.PrefetchOptions{ | 26838 | return std.builtin.PrefetchOptions{ |
| 26929 | .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), | 26839 | .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val), |
| ... | @@ -26945,7 +26855,7 @@ fn zirPrefetch( | ... | @@ -26945,7 +26855,7 @@ fn zirPrefetch( |
| 26945 | | 26855 | |
| 26946 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); | 26856 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 26947 | | 26857 | |
| 26948 | if (!block.is_comptime) { | 26858 | if (!block.isComptime()) { |
| 26949 | _ = try block.addInst(.{ | 26859 | _ = try block.addInst(.{ |
| 26950 | .tag = .prefetch, | 26860 | .tag = .prefetch, |
| 26951 | .data = .{ .prefetch = .{ | 26861 | .data = .{ .prefetch = .{ |
| ... | @@ -26987,30 +26897,20 @@ fn resolveExternOptions( | ... | @@ -26987,30 +26897,20 @@ fn resolveExternOptions( |
| 26987 | const dll_import_src = block.src(.{ .init_field_dll_import = src.offset.node_offset_builtin_call_arg.builtin_call_node }); | 26897 | const dll_import_src = block.src(.{ .init_field_dll_import = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26988 | | 26898 | |
| 26989 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); | 26899 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "name", .no_embedded_nulls), name_src); |
| 26990 | const name = try sema.toConstString(block, name_src, name_ref, .{ | 26900 | const name = try sema.toConstString(block, name_src, name_ref, .{ .simple = .extern_options }); |
| 26991 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", | | |
| 26992 | }); | | |
| 26993 | | 26901 | |
| 26994 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "library_name", .no_embedded_nulls), library_src); | 26902 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "library_name", .no_embedded_nulls), library_src); |
| 26995 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ | 26903 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ .simple = .extern_options }); |
| 26996 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", | | |
| 26997 | }); | | |
| 26998 | | 26904 | |
| 26999 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); | 26905 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "linkage", .no_embedded_nulls), linkage_src); |
| 27000 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ | 26906 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ .simple = .extern_options }); |
| 27001 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", | | |
| 27002 | }); | | |
| 27003 | const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); | 26907 | const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 27004 | | 26908 | |
| 27005 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src); | 26909 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src); |
| 27006 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ | 26910 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ .simple = .extern_options }); |
| 27007 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", | | |
| 27008 | }); | | |
| 27009 | | 26911 | |
| 27010 | const library_name = if (library_name_val.optionalValue(zcu)) |library_name_payload| library_name: { | 26912 | const library_name = if (library_name_val.optionalValue(zcu)) |library_name_payload| library_name: { |
| 27011 | const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{ | 26913 | const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{ .simple = .extern_options }); |
| 27012 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", | | |
| 27013 | }); | | |
| 27014 | if (library_name.len == 0) { | 26914 | if (library_name.len == 0) { |
| 27015 | return sema.fail(block, library_src, "library name cannot be empty", .{}); | 26915 | return sema.fail(block, library_src, "library name cannot be empty", .{}); |
| 27016 | } | 26916 | } |
| ... | @@ -27019,9 +26919,7 @@ fn resolveExternOptions( | ... | @@ -27019,9 +26919,7 @@ fn resolveExternOptions( |
| 27019 | } else null; | 26919 | } else null; |
| 27020 | | 26920 | |
| 27021 | const is_dll_import_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_dll_import", .no_embedded_nulls), dll_import_src); | 26921 | const is_dll_import_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_dll_import", .no_embedded_nulls), dll_import_src); |
| 27022 | const is_dll_import_val = try sema.resolveConstDefinedValue(block, dll_import_src, is_dll_import_ref, .{ | 26922 | const is_dll_import_val = try sema.resolveConstDefinedValue(block, dll_import_src, is_dll_import_ref, .{ .simple = .extern_options }); |
| 27023 | .needed_comptime_reason = "it must be comptime-known if the symbol is imported from a dll", | | |
| 27024 | }); | | |
| 27025 | | 26923 | |
| 27026 | if (name.len == 0) { | 26924 | if (name.len == 0) { |
| 27027 | return sema.fail(block, name_src, "extern symbol name cannot be empty", .{}); | 26925 | return sema.fail(block, name_src, "extern symbol name cannot be empty", .{}); |
| ... | @@ -27134,9 +27032,7 @@ fn zirWorkItem( | ... | @@ -27134,9 +27032,7 @@ fn zirWorkItem( |
| 27134 | }, | 27032 | }, |
| 27135 | } | 27033 | } |
| 27136 | | 27034 | |
| 27137 | const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{ | 27035 | const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{ .simple = .work_group_dim_index })); |
| 27138 | .needed_comptime_reason = "dimension must be comptime-known", | | |
| 27139 | })); | | |
| 27140 | try sema.requireRuntimeBlock(block, builtin_src, null); | 27036 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 27141 | | 27037 | |
| 27142 | return block.addInst(.{ | 27038 | return block.addInst(.{ |
| ... | @@ -27158,7 +27054,7 @@ fn zirInComptime( | ... | @@ -27158,7 +27054,7 @@ fn zirInComptime( |
| 27158 | block: *Block, | 27054 | block: *Block, |
| 27159 | ) CompileError!Air.Inst.Ref { | 27055 | ) CompileError!Air.Inst.Ref { |
| 27160 | _ = sema; | 27056 | _ = sema; |
| 27161 | return if (block.is_comptime) .bool_true else .bool_false; | 27057 | return if (block.isComptime()) .bool_true else .bool_false; |
| 27162 | } | 27058 | } |
| 27163 | | 27059 | |
| 27164 | fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 27060 | fn zirBuiltinValue(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| ... | @@ -27249,9 +27145,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -27249,9 +27145,7 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 27249 | | 27145 | |
| 27250 | const hint_ty = try sema.getBuiltinType("BranchHint"); | 27146 | const hint_ty = try sema.getBuiltinType("BranchHint"); |
| 27251 | const coerced_hint = try sema.coerce(block, hint_ty, uncoerced_hint, operand_src); | 27147 | const coerced_hint = try sema.coerce(block, hint_ty, uncoerced_hint, operand_src); |
| 27252 | const hint_val = try sema.resolveConstDefinedValue(block, operand_src, coerced_hint, .{ | 27148 | const hint_val = try sema.resolveConstDefinedValue(block, operand_src, coerced_hint, .{ .simple = .operand_branchHint }); |
| 27253 | .needed_comptime_reason = "operand to '@branchHint' must be comptime-known", | | |
| 27254 | }); | | |
| 27255 | | 27149 | |
| 27256 | // We only apply the first hint in a branch. | 27150 | // We only apply the first hint in a branch. |
| 27257 | // This allows user-provided hints to override implicit cold hints. | 27151 | // This allows user-provided hints to override implicit cold hints. |
| ... | @@ -27261,20 +27155,20 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -27261,20 +27155,20 @@ fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 27261 | } | 27155 | } |
| 27262 | | 27156 | |
| 27263 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { | 27157 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| 27264 | if (block.is_comptime) { | 27158 | if (block.isComptime()) { |
| 27265 | const msg = msg: { | 27159 | const msg, const fail_block = msg: { |
| 27266 | const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{}); | 27160 | const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{}); |
| 27267 | errdefer msg.destroy(sema.gpa); | 27161 | errdefer msg.destroy(sema.gpa); |
| 27268 | | 27162 | |
| 27269 | if (runtime_src) |some| { | 27163 | if (runtime_src) |some| { |
| 27270 | try sema.errNote(some, msg, "operation is runtime due to this operand", .{}); | 27164 | try sema.errNote(some, msg, "operation is runtime due to this operand", .{}); |
| 27271 | } | 27165 | } |
| 27272 | if (block.comptime_reason) |some| { | 27166 | |
| 27273 | try some.explain(sema, msg); | 27167 | const fail_block = try block.explainWhyBlockIsComptime(msg); |
| 27274 | } | 27168 | |
| 27275 | break :msg msg; | 27169 | break :msg .{ msg, fail_block }; |
| 27276 | }; | 27170 | }; |
| 27277 | return sema.failWithOwnedErrorMsg(block, msg); | 27171 | return sema.failWithOwnedErrorMsg(fail_block, msg); |
| 27278 | } | 27172 | } |
| 27279 | } | 27173 | } |
| 27280 | | 27174 | |
| ... | @@ -27759,7 +27653,7 @@ fn addSafetyCheck( | ... | @@ -27759,7 +27653,7 @@ fn addSafetyCheck( |
| 27759 | panic_id: Zcu.PanicId, | 27653 | panic_id: Zcu.PanicId, |
| 27760 | ) !void { | 27654 | ) !void { |
| 27761 | const gpa = sema.gpa; | 27655 | const gpa = sema.gpa; |
| 27762 | assert(!parent_block.is_comptime); | 27656 | assert(!parent_block.isComptime()); |
| 27763 | | 27657 | |
| 27764 | var fail_block: Block = .{ | 27658 | var fail_block: Block = .{ |
| 27765 | .parent = parent_block, | 27659 | .parent = parent_block, |
| ... | @@ -27767,7 +27661,7 @@ fn addSafetyCheck( | ... | @@ -27767,7 +27661,7 @@ fn addSafetyCheck( |
| 27767 | .namespace = parent_block.namespace, | 27661 | .namespace = parent_block.namespace, |
| 27768 | .instructions = .{}, | 27662 | .instructions = .{}, |
| 27769 | .inlining = parent_block.inlining, | 27663 | .inlining = parent_block.inlining, |
| 27770 | .is_comptime = false, | 27664 | .comptime_reason = null, |
| 27771 | .src_base_inst = parent_block.src_base_inst, | 27665 | .src_base_inst = parent_block.src_base_inst, |
| 27772 | .type_name_ctx = parent_block.type_name_ctx, | 27666 | .type_name_ctx = parent_block.type_name_ctx, |
| 27773 | }; | 27667 | }; |
| ... | @@ -27874,7 +27768,7 @@ fn addSafetyCheckUnwrapError( | ... | @@ -27874,7 +27768,7 @@ fn addSafetyCheckUnwrapError( |
| 27874 | unwrap_err_tag: Air.Inst.Tag, | 27768 | unwrap_err_tag: Air.Inst.Tag, |
| 27875 | is_non_err_tag: Air.Inst.Tag, | 27769 | is_non_err_tag: Air.Inst.Tag, |
| 27876 | ) !void { | 27770 | ) !void { |
| 27877 | assert(!parent_block.is_comptime); | 27771 | assert(!parent_block.isComptime()); |
| 27878 | const ok = try parent_block.addUnOp(is_non_err_tag, operand); | 27772 | const ok = try parent_block.addUnOp(is_non_err_tag, operand); |
| 27879 | const gpa = sema.gpa; | 27773 | const gpa = sema.gpa; |
| 27880 | | 27774 | |
| ... | @@ -27884,7 +27778,7 @@ fn addSafetyCheckUnwrapError( | ... | @@ -27884,7 +27778,7 @@ fn addSafetyCheckUnwrapError( |
| 27884 | .namespace = parent_block.namespace, | 27778 | .namespace = parent_block.namespace, |
| 27885 | .instructions = .{}, | 27779 | .instructions = .{}, |
| 27886 | .inlining = parent_block.inlining, | 27780 | .inlining = parent_block.inlining, |
| 27887 | .is_comptime = false, | 27781 | .comptime_reason = null, |
| 27888 | .src_base_inst = parent_block.src_base_inst, | 27782 | .src_base_inst = parent_block.src_base_inst, |
| 27889 | .type_name_ctx = parent_block.type_name_ctx, | 27783 | .type_name_ctx = parent_block.type_name_ctx, |
| 27890 | }; | 27784 | }; |
| ... | @@ -27918,7 +27812,7 @@ fn addSafetyCheckIndexOob( | ... | @@ -27918,7 +27812,7 @@ fn addSafetyCheckIndexOob( |
| 27918 | len: Air.Inst.Ref, | 27812 | len: Air.Inst.Ref, |
| 27919 | cmp_op: Air.Inst.Tag, | 27813 | cmp_op: Air.Inst.Tag, |
| 27920 | ) !void { | 27814 | ) !void { |
| 27921 | assert(!parent_block.is_comptime); | 27815 | assert(!parent_block.isComptime()); |
| 27922 | const ok = try parent_block.addBinOp(cmp_op, index, len); | 27816 | const ok = try parent_block.addBinOp(cmp_op, index, len); |
| 27923 | return addSafetyCheckCall(sema, parent_block, src, ok, "outOfBounds", &.{ index, len }); | 27817 | return addSafetyCheckCall(sema, parent_block, src, ok, "outOfBounds", &.{ index, len }); |
| 27924 | } | 27818 | } |
| ... | @@ -27930,7 +27824,7 @@ fn addSafetyCheckInactiveUnionField( | ... | @@ -27930,7 +27824,7 @@ fn addSafetyCheckInactiveUnionField( |
| 27930 | active_tag: Air.Inst.Ref, | 27824 | active_tag: Air.Inst.Ref, |
| 27931 | wanted_tag: Air.Inst.Ref, | 27825 | wanted_tag: Air.Inst.Ref, |
| 27932 | ) !void { | 27826 | ) !void { |
| 27933 | assert(!parent_block.is_comptime); | 27827 | assert(!parent_block.isComptime()); |
| 27934 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); | 27828 | const ok = try parent_block.addBinOp(.cmp_eq, active_tag, wanted_tag); |
| 27935 | return addSafetyCheckCall(sema, parent_block, src, ok, "inactiveUnionField", &.{ active_tag, wanted_tag }); | 27829 | return addSafetyCheckCall(sema, parent_block, src, ok, "inactiveUnionField", &.{ active_tag, wanted_tag }); |
| 27936 | } | 27830 | } |
| ... | @@ -27944,7 +27838,7 @@ fn addSafetyCheckSentinelMismatch( | ... | @@ -27944,7 +27838,7 @@ fn addSafetyCheckSentinelMismatch( |
| 27944 | ptr: Air.Inst.Ref, | 27838 | ptr: Air.Inst.Ref, |
| 27945 | sentinel_index: Air.Inst.Ref, | 27839 | sentinel_index: Air.Inst.Ref, |
| 27946 | ) !void { | 27840 | ) !void { |
| 27947 | assert(!parent_block.is_comptime); | 27841 | assert(!parent_block.isComptime()); |
| 27948 | const pt = sema.pt; | 27842 | const pt = sema.pt; |
| 27949 | const zcu = pt.zcu; | 27843 | const zcu = pt.zcu; |
| 27950 | const expected_sentinel_val = maybe_sentinel orelse return; | 27844 | const expected_sentinel_val = maybe_sentinel orelse return; |
| ... | @@ -27986,7 +27880,7 @@ fn addSafetyCheckCall( | ... | @@ -27986,7 +27880,7 @@ fn addSafetyCheckCall( |
| 27986 | func_name: []const u8, | 27880 | func_name: []const u8, |
| 27987 | args: []const Air.Inst.Ref, | 27881 | args: []const Air.Inst.Ref, |
| 27988 | ) !void { | 27882 | ) !void { |
| 27989 | assert(!parent_block.is_comptime); | 27883 | assert(!parent_block.isComptime()); |
| 27990 | const gpa = sema.gpa; | 27884 | const gpa = sema.gpa; |
| 27991 | const pt = sema.pt; | 27885 | const pt = sema.pt; |
| 27992 | const zcu = pt.zcu; | 27886 | const zcu = pt.zcu; |
| ... | @@ -27997,7 +27891,7 @@ fn addSafetyCheckCall( | ... | @@ -27997,7 +27891,7 @@ fn addSafetyCheckCall( |
| 27997 | .namespace = parent_block.namespace, | 27891 | .namespace = parent_block.namespace, |
| 27998 | .instructions = .{}, | 27892 | .instructions = .{}, |
| 27999 | .inlining = parent_block.inlining, | 27893 | .inlining = parent_block.inlining, |
| 28000 | .is_comptime = false, | 27894 | .comptime_reason = null, |
| 28001 | .src_base_inst = parent_block.src_base_inst, | 27895 | .src_base_inst = parent_block.src_base_inst, |
| 28002 | .type_name_ctx = parent_block.type_name_ctx, | 27896 | .type_name_ctx = parent_block.type_name_ctx, |
| 28003 | }; | 27897 | }; |
| ... | @@ -29168,9 +29062,7 @@ fn elemPtr( | ... | @@ -29168,9 +29062,7 @@ fn elemPtr( |
| 29168 | .array, .vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), | 29062 | .array, .vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), |
| 29169 | .@"struct" => blk: { | 29063 | .@"struct" => blk: { |
| 29170 | // Tuple field access. | 29064 | // Tuple field access. |
| 29171 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ | 29065 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ .simple = .tuple_field_index }); |
| 29172 | .needed_comptime_reason = "tuple field access index must be comptime-known", | | |
| 29173 | }); | | |
| 29174 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); | 29066 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); |
| 29175 | break :blk try sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); | 29067 | break :blk try sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init); |
| 29176 | }, | 29068 | }, |
| ... | @@ -29225,9 +29117,7 @@ fn elemPtrOneLayerOnly( | ... | @@ -29225,9 +29117,7 @@ fn elemPtrOneLayerOnly( |
| 29225 | .array, .vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety), | 29117 | .array, .vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety), |
| 29226 | .@"struct" => blk: { | 29118 | .@"struct" => blk: { |
| 29227 | assert(child_ty.isTuple(zcu)); | 29119 | assert(child_ty.isTuple(zcu)); |
| 29228 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ | 29120 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ .simple = .tuple_field_index }); |
| 29229 | .needed_comptime_reason = "tuple field access index must be comptime-known", | | |
| 29230 | }); | | |
| 29231 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); | 29121 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); |
| 29232 | break :blk try sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); | 29122 | break :blk try sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false); |
| 29233 | }, | 29123 | }, |
| ... | @@ -29305,9 +29195,7 @@ fn elemVal( | ... | @@ -29305,9 +29195,7 @@ fn elemVal( |
| 29305 | }, | 29195 | }, |
| 29306 | .@"struct" => { | 29196 | .@"struct" => { |
| 29307 | // Tuple field access. | 29197 | // Tuple field access. |
| 29308 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ | 29198 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ .simple = .tuple_field_index }); |
| 29309 | .needed_comptime_reason = "tuple field access index must be comptime-known", | | |
| 29310 | }); | | |
| 29311 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); | 29199 | const index: u32 = @intCast(try index_val.toUnsignedIntSema(pt)); |
| 29312 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); | 29200 | return sema.tupleField(block, indexable_src, indexable, elem_index_src, index); |
| 29313 | }, | 29201 | }, |
| ... | @@ -30093,9 +29981,7 @@ fn coerceExtra( | ... | @@ -30093,9 +29981,7 @@ fn coerceExtra( |
| 30093 | const val = maybe_inst_val orelse { | 29981 | const val = maybe_inst_val orelse { |
| 30094 | if (dest_ty.zigTypeTag(zcu) == .comptime_int) { | 29982 | if (dest_ty.zigTypeTag(zcu) == .comptime_int) { |
| 30095 | if (!opts.report_err) return error.NotCoercible; | 29983 | if (!opts.report_err) return error.NotCoercible; |
| 30096 | return sema.failWithNeededComptime(block, inst_src, .{ | 29984 | return sema.failWithNeededComptime(block, inst_src, .{ .simple = .casted_to_comptime_int }); |
| 30097 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", | | |
| 30098 | }); | | |
| 30099 | } | 29985 | } |
| 30100 | break :float; | 29986 | break :float; |
| 30101 | }; | 29987 | }; |
| ... | @@ -30120,9 +30006,7 @@ fn coerceExtra( | ... | @@ -30120,9 +30006,7 @@ fn coerceExtra( |
| 30120 | if (dest_ty.zigTypeTag(zcu) == .comptime_int) { | 30006 | if (dest_ty.zigTypeTag(zcu) == .comptime_int) { |
| 30121 | if (!opts.report_err) return error.NotCoercible; | 30007 | if (!opts.report_err) return error.NotCoercible; |
| 30122 | if (opts.no_cast_to_comptime_int) return inst; | 30008 | if (opts.no_cast_to_comptime_int) return inst; |
| 30123 | return sema.failWithNeededComptime(block, inst_src, .{ | 30009 | return sema.failWithNeededComptime(block, inst_src, .{ .simple = .casted_to_comptime_int }); |
| 30124 | .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known", | | |
| 30125 | }); | | |
| 30126 | } | 30010 | } |
| 30127 | | 30011 | |
| 30128 | // integer widening | 30012 | // integer widening |
| ... | @@ -30158,9 +30042,7 @@ fn coerceExtra( | ... | @@ -30158,9 +30042,7 @@ fn coerceExtra( |
| 30158 | return Air.internedToRef(result_val.toIntern()); | 30042 | return Air.internedToRef(result_val.toIntern()); |
| 30159 | } else if (dest_ty.zigTypeTag(zcu) == .comptime_float) { | 30043 | } else if (dest_ty.zigTypeTag(zcu) == .comptime_float) { |
| 30160 | if (!opts.report_err) return error.NotCoercible; | 30044 | if (!opts.report_err) return error.NotCoercible; |
| 30161 | return sema.failWithNeededComptime(block, inst_src, .{ | 30045 | return sema.failWithNeededComptime(block, inst_src, .{ .simple = .casted_to_comptime_float }); |
| 30162 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", | | |
| 30163 | }); | | |
| 30164 | } | 30046 | } |
| 30165 | | 30047 | |
| 30166 | // float widening | 30048 | // float widening |
| ... | @@ -30175,9 +30057,7 @@ fn coerceExtra( | ... | @@ -30175,9 +30057,7 @@ fn coerceExtra( |
| 30175 | const val = maybe_inst_val orelse { | 30057 | const val = maybe_inst_val orelse { |
| 30176 | if (dest_ty.zigTypeTag(zcu) == .comptime_float) { | 30058 | if (dest_ty.zigTypeTag(zcu) == .comptime_float) { |
| 30177 | if (!opts.report_err) return error.NotCoercible; | 30059 | if (!opts.report_err) return error.NotCoercible; |
| 30178 | return sema.failWithNeededComptime(block, inst_src, .{ | 30060 | return sema.failWithNeededComptime(block, inst_src, .{ .simple = .casted_to_comptime_float }); |
| 30179 | .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known", | | |
| 30180 | }); | | |
| 30181 | } | 30061 | } |
| 30182 | break :int; | 30062 | break :int; |
| 30183 | }; | 30063 | }; |
| ... | @@ -32435,9 +32315,7 @@ fn coerceTupleToStruct( | ... | @@ -32435,9 +32315,7 @@ fn coerceTupleToStruct( |
| 32435 | field_refs[struct_field_index] = coerced; | 32315 | field_refs[struct_field_index] = coerced; |
| 32436 | if (struct_type.fieldIsComptime(ip, struct_field_index)) { | 32316 | if (struct_type.fieldIsComptime(ip, struct_field_index)) { |
| 32437 | const init_val = try sema.resolveValue(coerced) orelse { | 32317 | const init_val = try sema.resolveValue(coerced) orelse { |
| 32438 | return sema.failWithNeededComptime(block, field_src, .{ | 32318 | return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field }); |
| 32439 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | | |
| 32440 | }); | | |
| 32441 | }; | 32319 | }; |
| 32442 | | 32320 | |
| 32443 | const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[struct_field_index]); | 32321 | const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[struct_field_index]); |
| ... | @@ -32550,9 +32428,7 @@ fn coerceTupleToTuple( | ... | @@ -32550,9 +32428,7 @@ fn coerceTupleToTuple( |
| 32550 | field_refs[field_index] = coerced; | 32428 | field_refs[field_index] = coerced; |
| 32551 | if (default_val != .none) { | 32429 | if (default_val != .none) { |
| 32552 | const init_val = (try sema.resolveValue(coerced)) orelse { | 32430 | const init_val = (try sema.resolveValue(coerced)) orelse { |
| 32553 | return sema.failWithNeededComptime(block, field_src, .{ | 32431 | return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field }); |
| 32554 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | | |
| 32555 | }); | | |
| 32556 | }; | 32432 | }; |
| 32557 | | 32433 | |
| 32558 | if (!init_val.eql(Value.fromInterned(default_val), Type.fromInterned(field_ty), pt.zcu)) { | 32434 | if (!init_val.eql(Value.fromInterned(default_val), Type.fromInterned(field_ty), pt.zcu)) { |
| ... | @@ -32816,12 +32692,12 @@ fn analyzeRef( | ... | @@ -32816,12 +32692,12 @@ fn analyzeRef( |
| 32816 | // In a comptime context, the store would fail, since the operand is runtime-known. But that's | 32692 | // In a comptime context, the store would fail, since the operand is runtime-known. But that's |
| 32817 | // okay; we don't actually need this store to succeed, since we're creating a runtime value in a | 32693 | // okay; we don't actually need this store to succeed, since we're creating a runtime value in a |
| 32818 | // comptime scope, so the value can never be used aside from to get its type. | 32694 | // comptime scope, so the value can never be used aside from to get its type. |
| 32819 | if (!block.is_comptime) { | 32695 | if (!block.isComptime()) { |
| 32820 | try sema.storePtr(block, src, alloc, operand); | 32696 | try sema.storePtr(block, src, alloc, operand); |
| 32821 | } | 32697 | } |
| 32822 | | 32698 | |
| 32823 | // Cast to the constant pointer type. We do this directly rather than going via `coerce` to | 32699 | // Cast to the constant pointer type. We do this directly rather than going via `coerce` to |
| 32824 | // avoid errors in the `block.is_comptime` case. | 32700 | // avoid errors in the `block.isComptime()` case. |
| 32825 | return block.addBitCast(ptr_type, alloc); | 32701 | return block.addBitCast(ptr_type, alloc); |
| 32826 | } | 32702 | } |
| 32827 | | 32703 | |
| ... | @@ -33184,24 +33060,24 @@ fn analyzeSlice( | ... | @@ -33184,24 +33060,24 @@ fn analyzeSlice( |
| 33184 | array_ty = double_child_ty; | 33060 | array_ty = double_child_ty; |
| 33185 | elem_ty = double_child_ty.childType(zcu); | 33061 | elem_ty = double_child_ty.childType(zcu); |
| 33186 | } else { | 33062 | } else { |
| 33187 | const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]"; | | |
| 33188 | if (uncasted_end_opt == .none) { | 33063 | if (uncasted_end_opt == .none) { |
| 33189 | return sema.fail(block, src, bounds_error_message, .{}); | 33064 | return sema.fail(block, src, "slice of single-item pointer must be bounded", .{}); |
| 33190 | } | 33065 | } |
| 33191 | const start_value = try sema.resolveConstDefinedValue( | 33066 | const start_value = try sema.resolveConstDefinedValue( |
| 33192 | block, | 33067 | block, |
| 33193 | start_src, | 33068 | start_src, |
| 33194 | uncasted_start, | 33069 | uncasted_start, |
| 33195 | .{ .needed_comptime_reason = bounds_error_message }, | 33070 | .{ .simple = .slice_single_item_ptr_bounds }, |
| 33196 | ); | 33071 | ); |
| 33197 | | 33072 | |
| 33198 | const end_value = try sema.resolveConstDefinedValue( | 33073 | const end_value = try sema.resolveConstDefinedValue( |
| 33199 | block, | 33074 | block, |
| 33200 | end_src, | 33075 | end_src, |
| 33201 | uncasted_end_opt, | 33076 | uncasted_end_opt, |
| 33202 | .{ .needed_comptime_reason = bounds_error_message }, | 33077 | .{ .simple = .slice_single_item_ptr_bounds }, |
| 33203 | ); | 33078 | ); |
| 33204 | | 33079 | |
| | 33080 | const bounds_error_message = "slice of single-item pointer must have bounds [0..0], [0..1], or [1..1]"; |
| 33205 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { | 33081 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { |
| 33206 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { | 33082 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { |
| 33207 | const msg = msg: { | 33083 | const msg = msg: { |
| ... | @@ -33416,9 +33292,7 @@ fn analyzeSlice( | ... | @@ -33416,9 +33292,7 @@ fn analyzeSlice( |
| 33416 | if (sentinel_opt != .none) { | 33292 | if (sentinel_opt != .none) { |
| 33417 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); | 33293 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 33418 | try checkSentinelType(sema, block, sentinel_src, elem_ty); | 33294 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 33419 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ | 33295 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ .simple = .slice_sentinel }); |
| 33420 | .needed_comptime_reason = "slice sentinel must be comptime-known", | | |
| 33421 | }); | | |
| 33422 | } | 33296 | } |
| 33423 | // If we are slicing to the end of something that is sentinel-terminated | 33297 | // If we are slicing to the end of something that is sentinel-terminated |
| 33424 | // then the resulting slice type is also sentinel-terminated. | 33298 | // then the resulting slice type is also sentinel-terminated. |
| ... | @@ -33499,9 +33373,9 @@ fn analyzeSlice( | ... | @@ -33499,9 +33373,9 @@ fn analyzeSlice( |
| 33499 | runtime_src = end_src; | 33373 | runtime_src = end_src; |
| 33500 | } | 33374 | } |
| 33501 | | 33375 | |
| 33502 | if (!checked_start_lte_end and block.wantSafety() and !block.is_comptime) { | 33376 | if (!checked_start_lte_end and block.wantSafety() and !block.isComptime()) { |
| 33503 | // requirement: start <= end | 33377 | // requirement: start <= end |
| 33504 | assert(!block.is_comptime); | 33378 | assert(!block.isComptime()); |
| 33505 | try sema.requireRuntimeBlock(block, src, runtime_src.?); | 33379 | try sema.requireRuntimeBlock(block, src, runtime_src.?); |
| 33506 | const ok = try block.addBinOp(.cmp_lte, start, end); | 33380 | const ok = try block.addBinOp(.cmp_lte, start, end); |
| 33507 | try sema.addSafetyCheckCall(block, src, ok, "startGreaterThanEnd", &.{ start, end }); | 33381 | try sema.addSafetyCheckCall(block, src, ok, "startGreaterThanEnd", &.{ start, end }); |
| ... | @@ -35859,7 +35733,7 @@ fn backingIntType( | ... | @@ -35859,7 +35733,7 @@ fn backingIntType( |
| 35859 | .namespace = struct_type.namespace, | 35733 | .namespace = struct_type.namespace, |
| 35860 | .instructions = .{}, | 35734 | .instructions = .{}, |
| 35861 | .inlining = null, | 35735 | .inlining = null, |
| 35862 | .is_comptime = true, | 35736 | .comptime_reason = null, // set below if needed |
| 35863 | .src_base_inst = struct_type.zir_index, | 35737 | .src_base_inst = struct_type.zir_index, |
| 35864 | .type_name_ctx = struct_type.name, | 35738 | .type_name_ctx = struct_type.name, |
| 35865 | }; | 35739 | }; |
| ... | @@ -35899,6 +35773,10 @@ fn backingIntType( | ... | @@ -35899,6 +35773,10 @@ fn backingIntType( |
| 35899 | .base_node_inst = struct_type.zir_index, | 35773 | .base_node_inst = struct_type.zir_index, |
| 35900 | .offset = .{ .node_offset_container_tag = 0 }, | 35774 | .offset = .{ .node_offset_container_tag = 0 }, |
| 35901 | }; | 35775 | }; |
| | 35776 | block.comptime_reason = .{ .reason = .{ |
| | 35777 | .src = backing_int_src, |
| | 35778 | .r = .{ .simple = .type }, |
| | 35779 | } }; |
| 35902 | const backing_int_ty = blk: { | 35780 | const backing_int_ty = blk: { |
| 35903 | if (backing_int_body_len == 0) { | 35781 | if (backing_int_body_len == 0) { |
| 35904 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 35782 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| ... | @@ -36512,7 +36390,13 @@ fn structFields( | ... | @@ -36512,7 +36390,13 @@ fn structFields( |
| 36512 | .namespace = namespace_index, | 36390 | .namespace = namespace_index, |
| 36513 | .instructions = .{}, | 36391 | .instructions = .{}, |
| 36514 | .inlining = null, | 36392 | .inlining = null, |
| 36515 | .is_comptime = true, | 36393 | .comptime_reason = .{ .reason = .{ |
| | 36394 | .src = .{ |
| | 36395 | .base_node_inst = struct_type.zir_index, |
| | 36396 | .offset = .nodeOffset(0), |
| | 36397 | }, |
| | 36398 | .r = .{ .simple = .struct_fields }, |
| | 36399 | } }, |
| 36516 | .src_base_inst = struct_type.zir_index, | 36400 | .src_base_inst = struct_type.zir_index, |
| 36517 | .type_name_ctx = struct_type.name, | 36401 | .type_name_ctx = struct_type.name, |
| 36518 | }; | 36402 | }; |
| ... | @@ -36698,7 +36582,7 @@ fn structFieldInits( | ... | @@ -36698,7 +36582,7 @@ fn structFieldInits( |
| 36698 | .namespace = namespace_index, | 36582 | .namespace = namespace_index, |
| 36699 | .instructions = .{}, | 36583 | .instructions = .{}, |
| 36700 | .inlining = null, | 36584 | .inlining = null, |
| 36701 | .is_comptime = true, | 36585 | .comptime_reason = undefined, // set when `block_scope` is used |
| 36702 | .src_base_inst = struct_type.zir_index, | 36586 | .src_base_inst = struct_type.zir_index, |
| 36703 | .type_name_ctx = struct_type.name, | 36587 | .type_name_ctx = struct_type.name, |
| 36704 | }; | 36588 | }; |
| ... | @@ -36776,13 +36660,13 @@ fn structFieldInits( | ... | @@ -36776,13 +36660,13 @@ fn structFieldInits( |
| 36776 | .offset = .{ .container_field_value = @intCast(field_i) }, | 36660 | .offset = .{ .container_field_value = @intCast(field_i) }, |
| 36777 | }; | 36661 | }; |
| 36778 | | 36662 | |
| | 36663 | block_scope.comptime_reason = .{ .reason = .{ |
| | 36664 | .src = init_src, |
| | 36665 | .r = .{ .simple = .struct_field_default_value }, |
| | 36666 | } }; |
| 36779 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36667 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36780 | const coerced = try sema.coerce(&block_scope, field_ty, init, init_src); | 36668 | const coerced = try sema.coerce(&block_scope, field_ty, init, init_src); |
| 36781 | const default_val = try sema.resolveValue(coerced) orelse { | 36669 | const default_val = try sema.resolveConstValue(&block_scope, init_src, coerced, null); |
| 36782 | return sema.failWithNeededComptime(&block_scope, init_src, .{ | | |
| 36783 | .needed_comptime_reason = "struct field default value must be comptime-known", | | |
| 36784 | }); | | |
| 36785 | }; | | |
| 36786 | | 36670 | |
| 36787 | if (default_val.canMutateComptimeVarState(zcu)) { | 36671 | if (default_val.canMutateComptimeVarState(zcu)) { |
| 36788 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); | 36672 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| ... | @@ -36850,20 +36734,26 @@ fn unionFields( | ... | @@ -36850,20 +36734,26 @@ fn unionFields( |
| 36850 | const body = zir.bodySlice(extra_index, body_len); | 36734 | const body = zir.bodySlice(extra_index, body_len); |
| 36851 | extra_index += body.len; | 36735 | extra_index += body.len; |
| 36852 | | 36736 | |
| | 36737 | const src: LazySrcLoc = .{ |
| | 36738 | .base_node_inst = union_type.zir_index, |
| | 36739 | .offset = .nodeOffset(0), |
| | 36740 | }; |
| | 36741 | |
| 36853 | var block_scope: Block = .{ | 36742 | var block_scope: Block = .{ |
| 36854 | .parent = null, | 36743 | .parent = null, |
| 36855 | .sema = sema, | 36744 | .sema = sema, |
| 36856 | .namespace = union_type.namespace, | 36745 | .namespace = union_type.namespace, |
| 36857 | .instructions = .{}, | 36746 | .instructions = .{}, |
| 36858 | .inlining = null, | 36747 | .inlining = null, |
| 36859 | .is_comptime = true, | 36748 | .comptime_reason = .{ .reason = .{ |
| | 36749 | .src = src, |
| | 36750 | .r = .{ .simple = .union_fields }, |
| | 36751 | } }, |
| 36860 | .src_base_inst = union_type.zir_index, | 36752 | .src_base_inst = union_type.zir_index, |
| 36861 | .type_name_ctx = union_type.name, | 36753 | .type_name_ctx = union_type.name, |
| 36862 | }; | 36754 | }; |
| 36863 | defer assert(block_scope.instructions.items.len == 0); | 36755 | defer assert(block_scope.instructions.items.len == 0); |
| 36864 | | 36756 | |
| 36865 | const src = block_scope.nodeOffset(0); | | |
| 36866 | | | |
| 36867 | if (body.len != 0) { | 36757 | if (body.len != 0) { |
| 36868 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); | 36758 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); |
| 36869 | } | 36759 | } |
| ... | @@ -36993,9 +36883,7 @@ fn unionFields( | ... | @@ -36993,9 +36883,7 @@ fn unionFields( |
| 36993 | if (enum_field_vals.capacity() > 0) { | 36883 | if (enum_field_vals.capacity() > 0) { |
| 36994 | const enum_tag_val = if (tag_ref != .none) blk: { | 36884 | const enum_tag_val = if (tag_ref != .none) blk: { |
| 36995 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, value_src); | 36885 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, value_src); |
| 36996 | const val = try sema.resolveConstDefinedValue(&block_scope, value_src, coerced, .{ | 36886 | const val = try sema.resolveConstDefinedValue(&block_scope, value_src, coerced, .{ .simple = .enum_field_tag_value }); |
| 36997 | .needed_comptime_reason = "enum tag value must be comptime-known", | | |
| 36998 | }); | | |
| 36999 | last_tag_val = val; | 36887 | last_tag_val = val; |
| 37000 | | 36888 | |
| 37001 | break :blk val; | 36889 | break :blk val; |
| ... | @@ -37669,9 +37557,7 @@ pub fn analyzeAsAddressSpace( | ... | @@ -37669,9 +37557,7 @@ pub fn analyzeAsAddressSpace( |
| 37669 | const zcu = pt.zcu; | 37557 | const zcu = pt.zcu; |
| 37670 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); | 37558 | const addrspace_ty = try sema.getBuiltinType("AddressSpace"); |
| 37671 | const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); | 37559 | const coerced = try sema.coerce(block, addrspace_ty, air_ref, src); |
| 37672 | const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ | 37560 | const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{ .simple = .@"addrspace" }); |
| 37673 | .needed_comptime_reason = "address space must be comptime-known", | | |
| 37674 | }); | | |
| 37675 | const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val); | 37561 | const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val); |
| 37676 | const target = pt.zcu.getTarget(); | 37562 | const target = pt.zcu.getTarget(); |
| 37677 | const arch = target.cpu.arch; | 37563 | const arch = target.cpu.arch; |
| ... | @@ -38560,7 +38446,7 @@ fn sliceToIpString( | ... | @@ -38560,7 +38446,7 @@ fn sliceToIpString( |
| 38560 | block: *Block, | 38446 | block: *Block, |
| 38561 | src: LazySrcLoc, | 38447 | src: LazySrcLoc, |
| 38562 | slice_val: Value, | 38448 | slice_val: Value, |
| 38563 | reason: NeededComptimeReason, | 38449 | reason: ComptimeReason, |
| 38564 | ) CompileError!InternPool.NullTerminatedString { | 38450 | ) CompileError!InternPool.NullTerminatedString { |
| 38565 | const pt = sema.pt; | 38451 | const pt = sema.pt; |
| 38566 | const zcu = pt.zcu; | 38452 | const zcu = pt.zcu; |
| ... | @@ -38580,7 +38466,7 @@ fn derefSliceAsArray( | ... | @@ -38580,7 +38466,7 @@ fn derefSliceAsArray( |
| 38580 | block: *Block, | 38466 | block: *Block, |
| 38581 | src: LazySrcLoc, | 38467 | src: LazySrcLoc, |
| 38582 | slice_val: Value, | 38468 | slice_val: Value, |
| 38583 | reason: NeededComptimeReason, | 38469 | reason: ComptimeReason, |
| 38584 | ) CompileError!Value { | 38470 | ) CompileError!Value { |
| 38585 | return try sema.maybeDerefSliceAsArray(block, src, slice_val) orelse { | 38471 | return try sema.maybeDerefSliceAsArray(block, src, slice_val) orelse { |
| 38586 | return sema.failWithNeededComptime(block, src, reason); | 38472 | return sema.failWithNeededComptime(block, src, reason); |
| ... | @@ -38734,7 +38620,10 @@ pub fn resolveDeclaredEnum( | ... | @@ -38734,7 +38620,10 @@ pub fn resolveDeclaredEnum( |
| 38734 | .namespace = namespace, | 38620 | .namespace = namespace, |
| 38735 | .instructions = .{}, | 38621 | .instructions = .{}, |
| 38736 | .inlining = null, | 38622 | .inlining = null, |
| 38737 | .is_comptime = true, | 38623 | .comptime_reason = .{ .reason = .{ |
| | 38624 | .src = src, |
| | 38625 | .r = .{ .simple = .enum_fields }, |
| | 38626 | } }, |
| 38738 | .src_base_inst = tracked_inst, | 38627 | .src_base_inst = tracked_inst, |
| 38739 | .type_name_ctx = type_name, | 38628 | .type_name_ctx = type_name, |
| 38740 | }; | 38629 | }; |
| ... | @@ -38798,9 +38687,7 @@ pub fn resolveDeclaredEnum( | ... | @@ -38798,9 +38687,7 @@ pub fn resolveDeclaredEnum( |
| 38798 | last_tag_val = try sema.resolveConstDefinedValue(&block, .{ | 38687 | last_tag_val = try sema.resolveConstDefinedValue(&block, .{ |
| 38799 | .base_node_inst = tracked_inst, | 38688 | .base_node_inst = tracked_inst, |
| 38800 | .offset = .{ .container_field_name = field_i }, | 38689 | .offset = .{ .container_field_name = field_i }, |
| 38801 | }, tag_inst, .{ | 38690 | }, tag_inst, .{ .simple = .enum_field_tag_value }); |
| 38802 | .needed_comptime_reason = "enum tag value must be comptime-known", | | |
| 38803 | }); | | |
| 38804 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; | 38691 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; |
| 38805 | last_tag_val = try pt.getCoerced(last_tag_val.?, int_tag_ty); | 38692 | last_tag_val = try pt.getCoerced(last_tag_val.?, int_tag_ty); |
| 38806 | if (wip_ty.nextField(ip, field_name, last_tag_val.?.toIntern())) |conflict| { | 38693 | if (wip_ty.nextField(ip, field_name, last_tag_val.?.toIntern())) |conflict| { |
| ... | @@ -38879,9 +38766,7 @@ fn getPanicInnerFn( | ... | @@ -38879,9 +38766,7 @@ fn getPanicInnerFn( |
| 38879 | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); | 38766 | const inner_name_ip = try ip.getOrPutString(gpa, pt.tid, inner_name, .no_embedded_nulls); |
| 38880 | const opt_fn_ref = try namespaceLookupVal(sema, block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); | 38767 | const opt_fn_ref = try namespaceLookupVal(sema, block, src, outer_ty.getNamespaceIndex(zcu), inner_name_ip); |
| 38881 | const fn_ref = opt_fn_ref orelse return sema.fail(block, src, "std.builtin.Panic missing {s}", .{inner_name}); | 38768 | const fn_ref = opt_fn_ref orelse return sema.fail(block, src, "std.builtin.Panic missing {s}", .{inner_name}); |
| 38882 | const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{ | 38769 | const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{ .simple = .panic_handler }); |
| 38883 | .needed_comptime_reason = "panic handler must be comptime-known", | | |
| 38884 | }); | | |
| 38885 | if (fn_val.typeOf(zcu).zigTypeTag(zcu) != .@"fn") { | 38770 | if (fn_val.typeOf(zcu).zigTypeTag(zcu) != .@"fn") { |
| 38886 | return sema.fail(block, src, "std.builtin.Panic.{s} is not a function", .{inner_name}); | 38771 | return sema.fail(block, src, "std.builtin.Panic.{s} is not a function", .{inner_name}); |
| 38887 | } | 38772 | } |
| ... | @@ -38963,9 +38848,7 @@ pub fn resolveNavPtrModifiers( | ... | @@ -38963,9 +38848,7 @@ pub fn resolveNavPtrModifiers( |
| 38963 | const @"linksection": InternPool.OptionalNullTerminatedString = ls: { | 38848 | const @"linksection": InternPool.OptionalNullTerminatedString = ls: { |
| 38964 | const linksection_body = zir_decl.linksection_body orelse break :ls .none; | 38849 | const linksection_body = zir_decl.linksection_body orelse break :ls .none; |
| 38965 | const linksection_ref = try sema.resolveInlineBody(block, linksection_body, decl_inst); | 38850 | const linksection_ref = try sema.resolveInlineBody(block, linksection_body, decl_inst); |
| 38966 | const bytes = try sema.toConstString(block, section_src, linksection_ref, .{ | 38851 | const bytes = try sema.toConstString(block, section_src, linksection_ref, .{ .simple = .@"linksection" }); |
| 38967 | .needed_comptime_reason = "linksection must be comptime-known", | | |
| 38968 | }); | | |
| 38969 | if (std.mem.indexOfScalar(u8, bytes, 0) != null) { | 38852 | if (std.mem.indexOfScalar(u8, bytes, 0) != null) { |
| 38970 | return sema.fail(block, section_src, "linksection cannot contain null bytes", .{}); | 38853 | return sema.fail(block, section_src, "linksection cannot contain null bytes", .{}); |
| 38971 | } else if (bytes.len == 0) { | 38854 | } else if (bytes.len == 0) { |