| ... | @@ -892,7 +892,7 @@ fn analyzeBodyInner( | ... | @@ -892,7 +892,7 @@ fn analyzeBodyInner( |
| 892 | .shl_sat => try sema.zirShl(block, inst, .shl_sat), | 892 | .shl_sat => try sema.zirShl(block, inst, .shl_sat), |
| 893 | | 893 | |
| 894 | .ret_ptr => try sema.zirRetPtr(block, inst), | 894 | .ret_ptr => try sema.zirRetPtr(block, inst), |
| 895 | .ret_type => try sema.zirRetType(block, inst), | 895 | .ret_type => try sema.addType(sema.fn_ret_ty), |
| 896 | | 896 | |
| 897 | // Instructions that we know to *always* be noreturn based solely on their tag. | 897 | // Instructions that we know to *always* be noreturn based solely on their tag. |
| 898 | // These functions match the return type of analyzeBody so that we can | 898 | // These functions match the return type of analyzeBody so that we can |
| ... | @@ -1173,7 +1173,7 @@ fn analyzeBodyInner( | ... | @@ -1173,7 +1173,7 @@ fn analyzeBodyInner( |
| 1173 | } else { | 1173 | } else { |
| 1174 | const src_node = sema.code.instructions.items(.data)[inst].node; | 1174 | const src_node = sema.code.instructions.items(.data)[inst].node; |
| 1175 | const src = LazySrcLoc.nodeOffset(src_node); | 1175 | const src = LazySrcLoc.nodeOffset(src_node); |
| 1176 | try sema.requireRuntimeBlock(block, src); | 1176 | try sema.requireFunctionBlock(block, src); |
| 1177 | break always_noreturn; | 1177 | break always_noreturn; |
| 1178 | } | 1178 | } |
| 1179 | }, | 1179 | }, |
| ... | @@ -1303,7 +1303,7 @@ fn analyzeBodyInner( | ... | @@ -1303,7 +1303,7 @@ fn analyzeBodyInner( |
| 1303 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1303 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1304 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; | 1304 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; |
| 1305 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1305 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; |
| 1306 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition); | 1306 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime known"); |
| 1307 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1307 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1308 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse | 1308 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1309 | break always_noreturn; | 1309 | break always_noreturn; |
| ... | @@ -1319,7 +1319,7 @@ fn analyzeBodyInner( | ... | @@ -1319,7 +1319,7 @@ fn analyzeBodyInner( |
| 1319 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1319 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1320 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; | 1320 | const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len]; |
| 1321 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; | 1321 | const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len]; |
| 1322 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition); | 1322 | const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime known"); |
| 1323 | const inline_body = if (cond.val.toBool()) then_body else else_body; | 1323 | const inline_body = if (cond.val.toBool()) then_body else else_body; |
| 1324 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse | 1324 | const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse |
| 1325 | break always_noreturn; | 1325 | break always_noreturn; |
| ... | @@ -1339,7 +1339,7 @@ fn analyzeBodyInner( | ... | @@ -1339,7 +1339,7 @@ fn analyzeBodyInner( |
| 1339 | const err_union = try sema.resolveInst(extra.data.operand); | 1339 | const err_union = try sema.resolveInst(extra.data.operand); |
| 1340 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1340 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1341 | assert(is_non_err != .none); | 1341 | assert(is_non_err != .none); |
| 1342 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); | 1342 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err, "try operand inside comptime block must be comptime known"); |
| 1343 | if (is_non_err_tv.val.toBool()) { | 1343 | if (is_non_err_tv.val.toBool()) { |
| 1344 | const err_union_ty = sema.typeOf(err_union); | 1344 | const err_union_ty = sema.typeOf(err_union); |
| 1345 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); | 1345 | break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false); |
| ... | @@ -1395,7 +1395,7 @@ fn analyzeBodyInner( | ... | @@ -1395,7 +1395,7 @@ fn analyzeBodyInner( |
| 1395 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); | 1395 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1396 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); | 1396 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1397 | assert(is_non_err != .none); | 1397 | assert(is_non_err != .none); |
| 1398 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err); | 1398 | const is_non_err_tv = try sema.resolveInstConst(block, operand_src, is_non_err, "try operand inside comptime block must be comptime known"); |
| 1399 | if (is_non_err_tv.val.toBool()) { | 1399 | if (is_non_err_tv.val.toBool()) { |
| 1400 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 1400 | break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 1401 | } | 1401 | } |
| ... | @@ -1478,11 +1478,12 @@ fn resolveConstBool( | ... | @@ -1478,11 +1478,12 @@ fn resolveConstBool( |
| 1478 | block: *Block, | 1478 | block: *Block, |
| 1479 | src: LazySrcLoc, | 1479 | src: LazySrcLoc, |
| 1480 | zir_ref: Zir.Inst.Ref, | 1480 | zir_ref: Zir.Inst.Ref, |
| | 1481 | reason: []const u8, |
| 1481 | ) !bool { | 1482 | ) !bool { |
| 1482 | const air_inst = try sema.resolveInst(zir_ref); | 1483 | const air_inst = try sema.resolveInst(zir_ref); |
| 1483 | const wanted_type = Type.bool; | 1484 | const wanted_type = Type.bool; |
| 1484 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 1485 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 1485 | const val = try sema.resolveConstValue(block, src, coerced_inst); | 1486 | const val = try sema.resolveConstValue(block, src, coerced_inst, reason); |
| 1486 | return val.toBool(); | 1487 | return val.toBool(); |
| 1487 | } | 1488 | } |
| 1488 | | 1489 | |
| ... | @@ -1491,11 +1492,12 @@ pub fn resolveConstString( | ... | @@ -1491,11 +1492,12 @@ pub fn resolveConstString( |
| 1491 | block: *Block, | 1492 | block: *Block, |
| 1492 | src: LazySrcLoc, | 1493 | src: LazySrcLoc, |
| 1493 | zir_ref: Zir.Inst.Ref, | 1494 | zir_ref: Zir.Inst.Ref, |
| | 1495 | reason: []const u8, |
| 1494 | ) ![]u8 { | 1496 | ) ![]u8 { |
| 1495 | const air_inst = try sema.resolveInst(zir_ref); | 1497 | const air_inst = try sema.resolveInst(zir_ref); |
| 1496 | const wanted_type = Type.initTag(.const_slice_u8); | 1498 | const wanted_type = Type.initTag(.const_slice_u8); |
| 1497 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 1499 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 1498 | const val = try sema.resolveConstValue(block, src, coerced_inst); | 1500 | const val = try sema.resolveConstValue(block, src, coerced_inst, reason); |
| 1499 | return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod); | 1501 | return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod); |
| 1500 | } | 1502 | } |
| 1501 | | 1503 | |
| ... | @@ -1514,7 +1516,7 @@ fn analyzeAsType( | ... | @@ -1514,7 +1516,7 @@ fn analyzeAsType( |
| 1514 | ) !Type { | 1516 | ) !Type { |
| 1515 | const wanted_type = Type.initTag(.@"type"); | 1517 | const wanted_type = Type.initTag(.@"type"); |
| 1516 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); | 1518 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 1517 | const val = try sema.resolveConstValue(block, src, coerced_inst); | 1519 | const val = try sema.resolveConstValue(block, src, coerced_inst, "types must be comptime known"); |
| 1518 | var buffer: Value.ToTypeBuffer = undefined; | 1520 | var buffer: Value.ToTypeBuffer = undefined; |
| 1519 | const ty = val.toType(&buffer); | 1521 | const ty = val.toType(&buffer); |
| 1520 | return ty.copy(sema.arena); | 1522 | return ty.copy(sema.arena); |
| ... | @@ -1567,12 +1569,13 @@ fn resolveValue( | ... | @@ -1567,12 +1569,13 @@ fn resolveValue( |
| 1567 | block: *Block, | 1569 | block: *Block, |
| 1568 | src: LazySrcLoc, | 1570 | src: LazySrcLoc, |
| 1569 | air_ref: Air.Inst.Ref, | 1571 | air_ref: Air.Inst.Ref, |
| | 1572 | reason: []const u8, |
| 1570 | ) CompileError!Value { | 1573 | ) CompileError!Value { |
| 1571 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { | 1574 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { |
| 1572 | if (val.tag() == .generic_poison) return error.GenericPoison; | 1575 | if (val.tag() == .generic_poison) return error.GenericPoison; |
| 1573 | return val; | 1576 | return val; |
| 1574 | } | 1577 | } |
| 1575 | return sema.failWithNeededComptime(block, src); | 1578 | return sema.failWithNeededComptime(block, src, reason); |
| 1576 | } | 1579 | } |
| 1577 | | 1580 | |
| 1578 | /// Value Tag `variable` will cause a compile error. | 1581 | /// Value Tag `variable` will cause a compile error. |
| ... | @@ -1582,15 +1585,16 @@ fn resolveConstMaybeUndefVal( | ... | @@ -1582,15 +1585,16 @@ fn resolveConstMaybeUndefVal( |
| 1582 | block: *Block, | 1585 | block: *Block, |
| 1583 | src: LazySrcLoc, | 1586 | src: LazySrcLoc, |
| 1584 | inst: Air.Inst.Ref, | 1587 | inst: Air.Inst.Ref, |
| | 1588 | reason: []const u8, |
| 1585 | ) CompileError!Value { | 1589 | ) CompileError!Value { |
| 1586 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| { | 1590 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| { |
| 1587 | switch (val.tag()) { | 1591 | switch (val.tag()) { |
| 1588 | .variable => return sema.failWithNeededComptime(block, src), | 1592 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1589 | .generic_poison => return error.GenericPoison, | 1593 | .generic_poison => return error.GenericPoison, |
| 1590 | else => return val, | 1594 | else => return val, |
| 1591 | } | 1595 | } |
| 1592 | } | 1596 | } |
| 1593 | return sema.failWithNeededComptime(block, src); | 1597 | return sema.failWithNeededComptime(block, src, reason); |
| 1594 | } | 1598 | } |
| 1595 | | 1599 | |
| 1596 | /// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors. | 1600 | /// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors. |
| ... | @@ -1600,16 +1604,17 @@ fn resolveConstValue( | ... | @@ -1600,16 +1604,17 @@ fn resolveConstValue( |
| 1600 | block: *Block, | 1604 | block: *Block, |
| 1601 | src: LazySrcLoc, | 1605 | src: LazySrcLoc, |
| 1602 | air_ref: Air.Inst.Ref, | 1606 | air_ref: Air.Inst.Ref, |
| | 1607 | reason: []const u8, |
| 1603 | ) CompileError!Value { | 1608 | ) CompileError!Value { |
| 1604 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { | 1609 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| { |
| 1605 | switch (val.tag()) { | 1610 | switch (val.tag()) { |
| 1606 | .undef => return sema.failWithUseOfUndef(block, src), | 1611 | .undef => return sema.failWithUseOfUndef(block, src), |
| 1607 | .variable => return sema.failWithNeededComptime(block, src), | 1612 | .variable => return sema.failWithNeededComptime(block, src, reason), |
| 1608 | .generic_poison => return error.GenericPoison, | 1613 | .generic_poison => return error.GenericPoison, |
| 1609 | else => return val, | 1614 | else => return val, |
| 1610 | } | 1615 | } |
| 1611 | } | 1616 | } |
| 1612 | return sema.failWithNeededComptime(block, src); | 1617 | return sema.failWithNeededComptime(block, src, reason); |
| 1613 | } | 1618 | } |
| 1614 | | 1619 | |
| 1615 | /// Value Tag `variable` causes this function to return `null`. | 1620 | /// Value Tag `variable` causes this function to return `null`. |
| ... | @@ -1697,8 +1702,15 @@ fn resolveMaybeUndefValAllowVariables( | ... | @@ -1697,8 +1702,15 @@ fn resolveMaybeUndefValAllowVariables( |
| 1697 | } | 1702 | } |
| 1698 | } | 1703 | } |
| 1699 | | 1704 | |
| 1700 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 1705 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: []const u8) CompileError { |
| 1701 | return sema.fail(block, src, "unable to resolve comptime value", .{}); | 1706 | const msg = msg: { |
| | 1707 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); |
| | 1708 | errdefer msg.destroy(sema.gpa); |
| | 1709 | |
| | 1710 | try sema.errNote(block, src, msg, "{s}", .{reason}); |
| | 1711 | break :msg msg; |
| | 1712 | }; |
| | 1713 | return sema.failWithOwnedErrorMsg(block, msg); |
| 1702 | } | 1714 | } |
| 1703 | | 1715 | |
| 1704 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 1716 | fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| ... | @@ -1870,7 +1882,7 @@ fn analyzeAsAlign( | ... | @@ -1870,7 +1882,7 @@ fn analyzeAsAlign( |
| 1870 | src: LazySrcLoc, | 1882 | src: LazySrcLoc, |
| 1871 | air_ref: Air.Inst.Ref, | 1883 | air_ref: Air.Inst.Ref, |
| 1872 | ) !u32 { | 1884 | ) !u32 { |
| 1873 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty); | 1885 | const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime known"); |
| 1874 | const alignment = @intCast(u32, alignment_big); // We coerce to u16 in the prev line. | 1886 | const alignment = @intCast(u32, alignment_big); // We coerce to u16 in the prev line. |
| 1875 | if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{}); | 1887 | if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{}); |
| 1876 | if (!std.math.isPowerOfTwo(alignment)) { | 1888 | if (!std.math.isPowerOfTwo(alignment)) { |
| ... | @@ -1897,9 +1909,10 @@ fn resolveInt( | ... | @@ -1897,9 +1909,10 @@ fn resolveInt( |
| 1897 | src: LazySrcLoc, | 1909 | src: LazySrcLoc, |
| 1898 | zir_ref: Zir.Inst.Ref, | 1910 | zir_ref: Zir.Inst.Ref, |
| 1899 | dest_ty: Type, | 1911 | dest_ty: Type, |
| | 1912 | reason: []const u8, |
| 1900 | ) !u64 { | 1913 | ) !u64 { |
| 1901 | const air_ref = try sema.resolveInst(zir_ref); | 1914 | const air_ref = try sema.resolveInst(zir_ref); |
| 1902 | return analyzeAsInt(sema, block, src, air_ref, dest_ty); | 1915 | return analyzeAsInt(sema, block, src, air_ref, dest_ty, reason); |
| 1903 | } | 1916 | } |
| 1904 | | 1917 | |
| 1905 | fn analyzeAsInt( | 1918 | fn analyzeAsInt( |
| ... | @@ -1908,9 +1921,10 @@ fn analyzeAsInt( | ... | @@ -1908,9 +1921,10 @@ fn analyzeAsInt( |
| 1908 | src: LazySrcLoc, | 1921 | src: LazySrcLoc, |
| 1909 | air_ref: Air.Inst.Ref, | 1922 | air_ref: Air.Inst.Ref, |
| 1910 | dest_ty: Type, | 1923 | dest_ty: Type, |
| | 1924 | reason: []const u8, |
| 1911 | ) !u64 { | 1925 | ) !u64 { |
| 1912 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); | 1926 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| 1913 | const val = try sema.resolveConstValue(block, src, coerced); | 1927 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 1914 | const target = sema.mod.getTarget(); | 1928 | const target = sema.mod.getTarget(); |
| 1915 | return (try val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?; | 1929 | return (try val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?; |
| 1916 | } | 1930 | } |
| ... | @@ -1922,9 +1936,10 @@ pub fn resolveInstConst( | ... | @@ -1922,9 +1936,10 @@ pub fn resolveInstConst( |
| 1922 | block: *Block, | 1936 | block: *Block, |
| 1923 | src: LazySrcLoc, | 1937 | src: LazySrcLoc, |
| 1924 | zir_ref: Zir.Inst.Ref, | 1938 | zir_ref: Zir.Inst.Ref, |
| | 1939 | reason: []const u8, |
| 1925 | ) CompileError!TypedValue { | 1940 | ) CompileError!TypedValue { |
| 1926 | const air_ref = try sema.resolveInst(zir_ref); | 1941 | const air_ref = try sema.resolveInst(zir_ref); |
| 1927 | const val = try sema.resolveConstValue(block, src, air_ref); | 1942 | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| 1928 | return TypedValue{ | 1943 | return TypedValue{ |
| 1929 | .ty = sema.typeOf(air_ref), | 1944 | .ty = sema.typeOf(air_ref), |
| 1930 | .val = val, | 1945 | .val = val, |
| ... | @@ -1938,9 +1953,10 @@ pub fn resolveInstValue( | ... | @@ -1938,9 +1953,10 @@ pub fn resolveInstValue( |
| 1938 | block: *Block, | 1953 | block: *Block, |
| 1939 | src: LazySrcLoc, | 1954 | src: LazySrcLoc, |
| 1940 | zir_ref: Zir.Inst.Ref, | 1955 | zir_ref: Zir.Inst.Ref, |
| | 1956 | reason: []const u8, |
| 1941 | ) CompileError!TypedValue { | 1957 | ) CompileError!TypedValue { |
| 1942 | const air_ref = try sema.resolveInst(zir_ref); | 1958 | const air_ref = try sema.resolveInst(zir_ref); |
| 1943 | const val = try sema.resolveValue(block, src, air_ref); | 1959 | const val = try sema.resolveValue(block, src, air_ref, reason); |
| 1944 | return TypedValue{ | 1960 | return TypedValue{ |
| 1945 | .ty = sema.typeOf(air_ref), | 1961 | .ty = sema.typeOf(air_ref), |
| 1946 | .val = val, | 1962 | .val = val, |
| ... | @@ -1974,7 +1990,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1974,7 +1990,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1974 | defer trash_block.instructions.deinit(sema.gpa); | 1990 | defer trash_block.instructions.deinit(sema.gpa); |
| 1975 | const operand = try trash_block.addBitCast(pointee_ty, .void_value); | 1991 | const operand = try trash_block.addBitCast(pointee_ty, .void_value); |
| 1976 | | 1992 | |
| 1977 | try sema.requireRuntimeBlock(block, src); | 1993 | try sema.requireFunctionBlock(block, src); |
| 1978 | const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 1994 | const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 1979 | .pointee_type = pointee_ty, | 1995 | .pointee_type = pointee_ty, |
| 1980 | .@"align" = inferred_alloc.alignment, | 1996 | .@"align" = inferred_alloc.alignment, |
| ... | @@ -2259,7 +2275,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2259,7 +2275,7 @@ fn createAnonymousDeclTypeNamed( |
| 2259 | const arg = sema.inst_map.get(zir_inst).?; | 2275 | const arg = sema.inst_map.get(zir_inst).?; |
| 2260 | // The comptime call code in analyzeCall already did this, so we're | 2276 | // The comptime call code in analyzeCall already did this, so we're |
| 2261 | // just repeating it here and it's guaranteed to work. | 2277 | // just repeating it here and it's guaranteed to work. |
| 2262 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg) catch unreachable; | 2278 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch unreachable; |
| 2263 | | 2279 | |
| 2264 | if (arg_i != 0) try buf.appendSlice(","); | 2280 | if (arg_i != 0) try buf.appendSlice(","); |
| 2265 | try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)}); | 2281 | try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)}); |
| ... | @@ -2515,7 +2531,7 @@ fn zirEnumDecl( | ... | @@ -2515,7 +2531,7 @@ fn zirEnumDecl( |
| 2515 | // TODO: if we need to report an error here, use a source location | 2531 | // TODO: if we need to report an error here, use a source location |
| 2516 | // that points to this default value expression rather than the struct. | 2532 | // that points to this default value expression rather than the struct. |
| 2517 | // But only resolve the source location if we need to emit a compile error. | 2533 | // But only resolve the source location if we need to emit a compile error. |
| 2518 | const tag_val = (try sema.resolveInstConst(block, src, tag_val_ref)).val; | 2534 | const tag_val = (try sema.resolveInstConst(block, src, tag_val_ref, "enum tag value must be comptime known")).val; |
| 2519 | last_tag_val = tag_val; | 2535 | last_tag_val = tag_val; |
| 2520 | const copied_tag_val = try tag_val.copy(new_decl_arena_allocator); | 2536 | const copied_tag_val = try tag_val.copy(new_decl_arena_allocator); |
| 2521 | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ | 2537 | enum_obj.values.putAssumeCapacityNoClobberContext(copied_tag_val, {}, .{ |
| ... | @@ -2738,7 +2754,6 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -2738,7 +2754,6 @@ fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 2738 | | 2754 | |
| 2739 | const inst_data = sema.code.instructions.items(.data)[inst].node; | 2755 | const inst_data = sema.code.instructions.items(.data)[inst].node; |
| 2740 | const src = LazySrcLoc.nodeOffset(inst_data); | 2756 | const src = LazySrcLoc.nodeOffset(inst_data); |
| 2741 | try sema.requireFunctionBlock(block, src); | | |
| 2742 | | 2757 | |
| 2743 | if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) { | 2758 | if (block.is_comptime or try sema.typeRequiresComptime(block, src, sema.fn_ret_ty)) { |
| 2744 | const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty); | 2759 | const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty); |
| ... | @@ -2770,16 +2785,6 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -2770,16 +2785,6 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 2770 | return sema.analyzeRef(block, inst_data.src(), operand); | 2785 | return sema.analyzeRef(block, inst_data.src(), operand); |
| 2771 | } | 2786 | } |
| 2772 | | 2787 | |
| 2773 | fn zirRetType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | | |
| 2774 | const tracy = trace(@src()); | | |
| 2775 | defer tracy.end(); | | |
| 2776 | | | |
| 2777 | const inst_data = sema.code.instructions.items(.data)[inst].node; | | |
| 2778 | const src = LazySrcLoc.nodeOffset(inst_data); | | |
| 2779 | try sema.requireFunctionBlock(block, src); | | |
| 2780 | return sema.addType(sema.fn_ret_ty); | | |
| 2781 | } | | |
| 2782 | | | |
| 2783 | fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 2788 | fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 2784 | const tracy = trace(@src()); | 2789 | const tracy = trace(@src()); |
| 2785 | defer tracy.end(); | 2790 | defer tracy.end(); |
| ... | @@ -2925,7 +2930,7 @@ fn zirAllocExtended( | ... | @@ -2925,7 +2930,7 @@ fn zirAllocExtended( |
| 2925 | try sema.validateVarType(block, ty_src, var_ty, false); | 2930 | try sema.validateVarType(block, ty_src, var_ty, false); |
| 2926 | } | 2931 | } |
| 2927 | const target = sema.mod.getTarget(); | 2932 | const target = sema.mod.getTarget(); |
| 2928 | try sema.requireRuntimeBlock(block, src); | 2933 | try sema.requireFunctionBlock(block, src); |
| 2929 | try sema.resolveTypeLayout(block, src, var_ty); | 2934 | try sema.resolveTypeLayout(block, src, var_ty); |
| 2930 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ | 2935 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 2931 | .pointee_type = var_ty, | 2936 | .pointee_type = var_ty, |
| ... | @@ -3024,7 +3029,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3024,7 +3029,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3024 | return sema.addConstant(const_ptr_ty, val); | 3029 | return sema.addConstant(const_ptr_ty, val); |
| 3025 | } | 3030 | } |
| 3026 | | 3031 | |
| 3027 | try sema.requireRuntimeBlock(block, src); | 3032 | try sema.requireFunctionBlock(block, src); |
| 3028 | return block.addBitCast(const_ptr_ty, alloc); | 3033 | return block.addBitCast(const_ptr_ty, alloc); |
| 3029 | } | 3034 | } |
| 3030 | | 3035 | |
| ... | @@ -3061,7 +3066,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -3061,7 +3066,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 3061 | .pointee_type = var_ty, | 3066 | .pointee_type = var_ty, |
| 3062 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 3067 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 3063 | }); | 3068 | }); |
| 3064 | try sema.requireRuntimeBlock(block, var_decl_src); | 3069 | try sema.requireFunctionBlock(block, var_decl_src); |
| 3065 | try sema.queueFullTypeResolution(var_ty); | 3070 | try sema.queueFullTypeResolution(var_ty); |
| 3066 | return block.addTy(.alloc, ptr_type); | 3071 | return block.addTy(.alloc, ptr_type); |
| 3067 | } | 3072 | } |
| ... | @@ -3083,7 +3088,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -3083,7 +3088,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 3083 | .pointee_type = var_ty, | 3088 | .pointee_type = var_ty, |
| 3084 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 3089 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 3085 | }); | 3090 | }); |
| 3086 | try sema.requireRuntimeBlock(block, var_decl_src); | 3091 | try sema.requireFunctionBlock(block, var_decl_src); |
| 3087 | try sema.queueFullTypeResolution(var_ty); | 3092 | try sema.queueFullTypeResolution(var_ty); |
| 3088 | return block.addTy(.alloc, ptr_type); | 3093 | return block.addTy(.alloc, ptr_type); |
| 3089 | } | 3094 | } |
| ... | @@ -3272,7 +3277,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3272,7 +3277,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3272 | return; | 3277 | return; |
| 3273 | } | 3278 | } |
| 3274 | | 3279 | |
| 3275 | try sema.requireRuntimeBlock(block, src); | 3280 | try sema.requireFunctionBlock(block, src); |
| 3276 | try sema.queueFullTypeResolution(final_elem_ty); | 3281 | try sema.queueFullTypeResolution(final_elem_ty); |
| 3277 | | 3282 | |
| 3278 | // Change it to a normal alloc. | 3283 | // Change it to a normal alloc. |
| ... | @@ -3593,7 +3598,7 @@ fn validateUnionInit( | ... | @@ -3593,7 +3598,7 @@ fn validateUnionInit( |
| 3593 | return; | 3598 | return; |
| 3594 | } | 3599 | } |
| 3595 | | 3600 | |
| 3596 | try sema.requireRuntimeBlock(block, init_src); | 3601 | try sema.requireFunctionBlock(block, init_src); |
| 3597 | const new_tag = try sema.addConstant(union_obj.tag_ty, tag_val); | 3602 | const new_tag = try sema.addConstant(union_obj.tag_ty, tag_val); |
| 3598 | _ = try block.addBinOp(.set_union_tag, union_ptr, new_tag); | 3603 | _ = try block.addBinOp(.set_union_tag, union_ptr, new_tag); |
| 3599 | } | 3604 | } |
| ... | @@ -3859,7 +3864,7 @@ fn zirValidateArrayInit( | ... | @@ -3859,7 +3864,7 @@ fn zirValidateArrayInit( |
| 3859 | // any ZIR instructions at comptime; we need to do that here. | 3864 | // any ZIR instructions at comptime; we need to do that here. |
| 3860 | if (array_ty.sentinel()) |sentinel_val| { | 3865 | if (array_ty.sentinel()) |sentinel_val| { |
| 3861 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); | 3866 | const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len); |
| 3862 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, array_ptr, init_src, array_len_ref, true); | 3867 | const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true); |
| 3863 | const sentinel = try sema.addConstant(array_ty.childType(), sentinel_val); | 3868 | const sentinel = try sema.addConstant(array_ty.childType(), sentinel_val); |
| 3864 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); | 3869 | try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store); |
| 3865 | } | 3870 | } |
| ... | @@ -4207,10 +4212,8 @@ fn storeToInferredAllocComptime( | ... | @@ -4207,10 +4212,8 @@ fn storeToInferredAllocComptime( |
| 4207 | const operand_ty = sema.typeOf(operand); | 4212 | const operand_ty = sema.typeOf(operand); |
| 4208 | // There will be only one store_to_inferred_ptr because we are running at comptime. | 4213 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 4209 | // The alloc will turn into a Decl. | 4214 | // The alloc will turn into a Decl. |
| 4210 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) |operand_val| { | 4215 | if (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) |operand_val| store: { |
| 4211 | if (operand_val.tag() == .variable) { | 4216 | if (operand_val.tag() == .variable) break :store; |
| 4212 | return sema.failWithNeededComptime(block, src); | | |
| 4213 | } | | |
| 4214 | var anon_decl = try block.startAnonDecl(src); | 4217 | var anon_decl = try block.startAnonDecl(src); |
| 4215 | defer anon_decl.deinit(); | 4218 | defer anon_decl.deinit(); |
| 4216 | iac.data.decl_index = try anon_decl.finish( | 4219 | iac.data.decl_index = try anon_decl.finish( |
| ... | @@ -4219,15 +4222,15 @@ fn storeToInferredAllocComptime( | ... | @@ -4219,15 +4222,15 @@ fn storeToInferredAllocComptime( |
| 4219 | iac.data.alignment, | 4222 | iac.data.alignment, |
| 4220 | ); | 4223 | ); |
| 4221 | return; | 4224 | return; |
| 4222 | } else { | | |
| 4223 | return sema.failWithNeededComptime(block, src); | | |
| 4224 | } | 4225 | } |
| | 4226 | |
| | 4227 | return sema.failWithNeededComptime(block, src, "value being stored to a comptime variable must be comptime known"); |
| 4225 | } | 4228 | } |
| 4226 | | 4229 | |
| 4227 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4230 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4228 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 4231 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4229 | const src = inst_data.src(); | 4232 | const src = inst_data.src(); |
| 4230 | const quota = @intCast(u32, try sema.resolveInt(block, src, inst_data.operand, Type.u32)); | 4233 | const quota = @intCast(u32, try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime known")); |
| 4231 | sema.branch_quota = @maximum(sema.branch_quota, quota); | 4234 | sema.branch_quota = @maximum(sema.branch_quota, quota); |
| 4232 | } | 4235 | } |
| 4233 | | 4236 | |
| ... | @@ -4282,7 +4285,7 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -4282,7 +4285,7 @@ fn zirParamType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 4282 | var param_index = inst_data.param_index; | 4285 | var param_index = inst_data.param_index; |
| 4283 | | 4286 | |
| 4284 | const fn_ty = if (callee_ty.tag() == .bound_fn) fn_ty: { | 4287 | const fn_ty = if (callee_ty.tag() == .bound_fn) fn_ty: { |
| 4285 | const bound_fn_val = try sema.resolveConstValue(block, callee_src, callee); | 4288 | const bound_fn_val = try sema.resolveConstValue(block, .unneeded, callee, undefined); |
| 4286 | const bound_fn = bound_fn_val.castTag(.bound_fn).?.data; | 4289 | const bound_fn = bound_fn_val.castTag(.bound_fn).?.data; |
| 4287 | const fn_ty = sema.typeOf(bound_fn.func_inst); | 4290 | const fn_ty = sema.typeOf(bound_fn.func_inst); |
| 4288 | param_index += 1; | 4291 | param_index += 1; |
| ... | @@ -4417,7 +4420,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -4417,7 +4420,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 4417 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 4420 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4418 | const src = inst_data.src(); | 4421 | const src = inst_data.src(); |
| 4419 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 4422 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 4420 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand); | 4423 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, "compile error string must be comptime known"); |
| 4421 | return sema.fail(block, src, "{s}", .{msg}); | 4424 | return sema.fail(block, src, "{s}", .{msg}); |
| 4422 | } | 4425 | } |
| 4423 | | 4426 | |
| ... | @@ -4466,7 +4469,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index, force_comptime: bo | ... | @@ -4466,7 +4469,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index, force_comptime: bo |
| 4466 | if (block.is_comptime or force_comptime) { | 4469 | if (block.is_comptime or force_comptime) { |
| 4467 | return sema.fail(block, src, "encountered @panic at comptime", .{}); | 4470 | return sema.fail(block, src, "encountered @panic at comptime", .{}); |
| 4468 | } | 4471 | } |
| 4469 | try sema.requireRuntimeBlock(block, src); | 4472 | try sema.requireFunctionBlock(block, src); |
| 4470 | return sema.panicWithMsg(block, src, msg_inst); | 4473 | return sema.panicWithMsg(block, src, msg_inst); |
| 4471 | } | 4474 | } |
| 4472 | | 4475 | |
| ... | @@ -4854,7 +4857,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -4854,7 +4857,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 4854 | const src = inst_data.src(); | 4857 | const src = inst_data.src(); |
| 4855 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 4858 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 4856 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 4859 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 4857 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand); | 4860 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, "export target must be comptime known"); |
| 4858 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 4861 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 4859 | const decl_index = switch (operand.val.tag()) { | 4862 | const decl_index = switch (operand.val.tag()) { |
| 4860 | .function => operand.val.castTag(.function).?.data.owner_decl, | 4863 | .function => operand.val.castTag(.function).?.data.owner_decl, |
| ... | @@ -4989,7 +4992,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -4989,7 +4992,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 4989 | fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4992 | fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4990 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 4993 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4991 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 4994 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 4992 | const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand); | 4995 | const is_cold = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setCold must be comptime known"); |
| 4993 | const func = sema.func orelse return; // does nothing outside a function | 4996 | const func = sema.func orelse return; // does nothing outside a function |
| 4994 | func.is_cold = is_cold; | 4997 | func.is_cold = is_cold; |
| 4995 | } | 4998 | } |
| ... | @@ -4997,7 +5000,7 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -4997,7 +5000,7 @@ fn zirSetCold(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 4997 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 5000 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 4998 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 5001 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 4999 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 5002 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 5000 | const float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode"); | 5003 | const float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", "operand to @setFloatMode must be comptime known"); |
| 5001 | switch (float_mode) { | 5004 | switch (float_mode) { |
| 5002 | .Strict => return, | 5005 | .Strict => return, |
| 5003 | .Optimized => { | 5006 | .Optimized => { |
| ... | @@ -5009,7 +5012,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -5009,7 +5012,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 5009 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5012 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5010 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 5013 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 5011 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5014 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 5012 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand); | 5015 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setRuntimeSafety must be comptime known"); |
| 5013 | } | 5016 | } |
| 5014 | | 5017 | |
| 5015 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 5018 | fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| ... | @@ -5017,7 +5020,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co | ... | @@ -5017,7 +5020,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co |
| 5017 | | 5020 | |
| 5018 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 5021 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 5019 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 5022 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 5020 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand); | 5023 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, "atomic order of @fence must be comptime known"); |
| 5021 | | 5024 | |
| 5022 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { | 5025 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { |
| 5023 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); | 5026 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| ... | @@ -5292,7 +5295,7 @@ fn zirCall( | ... | @@ -5292,7 +5295,7 @@ fn zirCall( |
| 5292 | | 5295 | |
| 5293 | // Desugar bound functions here | 5296 | // Desugar bound functions here |
| 5294 | if (func_type.tag() == .bound_fn) { | 5297 | if (func_type.tag() == .bound_fn) { |
| 5295 | const bound_func = try sema.resolveValue(block, func_src, func); | 5298 | const bound_func = try sema.resolveValue(block, .unneeded, func, undefined); |
| 5296 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; | 5299 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; |
| 5297 | func = bound_data.func_inst; | 5300 | func = bound_data.func_inst; |
| 5298 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len + 1); | 5301 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args.len + 1); |
| ... | @@ -5489,7 +5492,8 @@ fn analyzeCall( | ... | @@ -5489,7 +5492,8 @@ fn analyzeCall( |
| 5489 | } | 5492 | } |
| 5490 | | 5493 | |
| 5491 | const result: Air.Inst.Ref = if (is_inline_call) res: { | 5494 | const result: Air.Inst.Ref = if (is_inline_call) res: { |
| 5492 | const func_val = try sema.resolveConstValue(block, func_src, func); | 5495 | // TODO explain why function is being called at comptime |
| | 5496 | const func_val = try sema.resolveConstValue(block, func_src, func, "function being called at comptime must be comptime known"); |
| 5493 | const module_fn = switch (func_val.tag()) { | 5497 | const module_fn = switch (func_val.tag()) { |
| 5494 | .decl_ref => mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data, | 5498 | .decl_ref => mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data, |
| 5495 | .function => func_val.castTag(.function).?.data, | 5499 | .function => func_val.castTag(.function).?.data, |
| ... | @@ -5606,7 +5610,8 @@ fn analyzeCall( | ... | @@ -5606,7 +5610,8 @@ fn analyzeCall( |
| 5606 | try sema.inst_map.putNoClobber(gpa, inst, casted_arg); | 5610 | try sema.inst_map.putNoClobber(gpa, inst, casted_arg); |
| 5607 | | 5611 | |
| 5608 | if (is_comptime_call) { | 5612 | if (is_comptime_call) { |
| 5609 | const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, casted_arg); | 5613 | // TODO explain why function is being called at comptime |
| | 5614 | const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, casted_arg, "argument to function being called at comptime must be comptime known"); |
| 5610 | switch (arg_val.tag()) { | 5615 | switch (arg_val.tag()) { |
| 5611 | .generic_poison, .generic_poison_type => { | 5616 | .generic_poison, .generic_poison_type => { |
| 5612 | // This function is currently evaluated as part of an as-of-yet unresolvable | 5617 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -5638,7 +5643,8 @@ fn analyzeCall( | ... | @@ -5638,7 +5643,8 @@ fn analyzeCall( |
| 5638 | | 5643 | |
| 5639 | if (is_comptime_call) { | 5644 | if (is_comptime_call) { |
| 5640 | const arg_src = call_src; // TODO: better source location | 5645 | const arg_src = call_src; // TODO: better source location |
| 5641 | const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, uncasted_arg); | 5646 | // TODO explain why function is being called at comptime |
| | 5647 | const arg_val = try sema.resolveConstMaybeUndefVal(&child_block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime known"); |
| 5642 | switch (arg_val.tag()) { | 5648 | switch (arg_val.tag()) { |
| 5643 | .generic_poison, .generic_poison_type => { | 5649 | .generic_poison, .generic_poison_type => { |
| 5644 | // This function is currently evaluated as part of an as-of-yet unresolvable | 5650 | // This function is currently evaluated as part of an as-of-yet unresolvable |
| ... | @@ -5764,7 +5770,7 @@ fn analyzeCall( | ... | @@ -5764,7 +5770,7 @@ fn analyzeCall( |
| 5764 | } | 5770 | } |
| 5765 | | 5771 | |
| 5766 | if (should_memoize and is_comptime_call) { | 5772 | if (should_memoize and is_comptime_call) { |
| 5767 | const result_val = try sema.resolveConstMaybeUndefVal(block, call_src, result); | 5773 | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined); |
| 5768 | | 5774 | |
| 5769 | // TODO: check whether any external comptime memory was mutated by the | 5775 | // TODO: check whether any external comptime memory was mutated by the |
| 5770 | // comptime function call. If so, then do not memoize the call here. | 5776 | // comptime function call. If so, then do not memoize the call here. |
| ... | @@ -5795,7 +5801,7 @@ fn analyzeCall( | ... | @@ -5795,7 +5801,7 @@ fn analyzeCall( |
| 5795 | break :res res2; | 5801 | break :res res2; |
| 5796 | } else res: { | 5802 | } else res: { |
| 5797 | assert(!func_ty_info.is_generic); | 5803 | assert(!func_ty_info.is_generic); |
| 5798 | try sema.requireRuntimeBlock(block, call_src); | 5804 | try sema.requireFunctionBlock(block, call_src); |
| 5799 | | 5805 | |
| 5800 | const args = try sema.arena.alloc(Air.Inst.Ref, uncasted_args.len); | 5806 | const args = try sema.arena.alloc(Air.Inst.Ref, uncasted_args.len); |
| 5801 | for (uncasted_args) |uncasted_arg, i| { | 5807 | for (uncasted_args) |uncasted_arg, i| { |
| ... | @@ -5849,7 +5855,7 @@ fn instantiateGenericCall( | ... | @@ -5849,7 +5855,7 @@ fn instantiateGenericCall( |
| 5849 | const mod = sema.mod; | 5855 | const mod = sema.mod; |
| 5850 | const gpa = sema.gpa; | 5856 | const gpa = sema.gpa; |
| 5851 | | 5857 | |
| 5852 | const func_val = try sema.resolveConstValue(block, func_src, func); | 5858 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime known"); |
| 5853 | const module_fn = switch (func_val.tag()) { | 5859 | const module_fn = switch (func_val.tag()) { |
| 5854 | .function => func_val.castTag(.function).?.data, | 5860 | .function => func_val.castTag(.function).?.data, |
| 5855 | .decl_ref => mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data, | 5861 | .decl_ref => mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data, |
| ... | @@ -5902,7 +5908,7 @@ fn instantiateGenericCall( | ... | @@ -5902,7 +5908,7 @@ fn instantiateGenericCall( |
| 5902 | if (is_comptime) { | 5908 | if (is_comptime) { |
| 5903 | const arg_src = call_src; // TODO better source location | 5909 | const arg_src = call_src; // TODO better source location |
| 5904 | const arg_ty = sema.typeOf(uncasted_args[i]); | 5910 | const arg_ty = sema.typeOf(uncasted_args[i]); |
| 5905 | const arg_val = try sema.resolveValue(block, arg_src, uncasted_args[i]); | 5911 | const arg_val = try sema.resolveValue(block, arg_src, uncasted_args[i], "parameter is comptime"); |
| 5906 | try sema.resolveLazyValue(block, arg_src, arg_val); | 5912 | try sema.resolveLazyValue(block, arg_src, arg_val); |
| 5907 | arg_val.hash(arg_ty, &hasher, mod); | 5913 | arg_val.hash(arg_ty, &hasher, mod); |
| 5908 | if (is_anytype) { | 5914 | if (is_anytype) { |
| ... | @@ -6066,12 +6072,12 @@ fn instantiateGenericCall( | ... | @@ -6066,12 +6072,12 @@ fn instantiateGenericCall( |
| 6066 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); | 6072 | const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val); |
| 6067 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); | 6073 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 6068 | } else { | 6074 | } else { |
| 6069 | return sema.failWithNeededComptime(block, arg_src); | 6075 | return sema.failWithNeededComptime(block, arg_src, "parameter is comptime"); |
| 6070 | } | 6076 | } |
| 6071 | } else if (is_anytype) { | 6077 | } else if (is_anytype) { |
| 6072 | const arg_ty = sema.typeOf(arg); | 6078 | const arg_ty = sema.typeOf(arg); |
| 6073 | if (try sema.typeRequiresComptime(block, arg_src, arg_ty)) { | 6079 | if (try sema.typeRequiresComptime(block, arg_src, arg_ty)) { |
| 6074 | const arg_val = try sema.resolveConstValue(block, arg_src, arg); | 6080 | const arg_val = try sema.resolveConstValue(block, arg_src, arg, "type of anytype parameter requires comptime"); |
| 6075 | const child_arg = try child_sema.addConstant(arg_ty, arg_val); | 6081 | const child_arg = try child_sema.addConstant(arg_ty, arg_val); |
| 6076 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); | 6082 | child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg); |
| 6077 | } else { | 6083 | } else { |
| ... | @@ -6093,7 +6099,7 @@ fn instantiateGenericCall( | ... | @@ -6093,7 +6099,7 @@ fn instantiateGenericCall( |
| 6093 | } | 6099 | } |
| 6094 | return err; | 6100 | return err; |
| 6095 | }; | 6101 | }; |
| 6096 | const new_func_val = child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst) catch unreachable; | 6102 | const new_func_val = child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable; |
| 6097 | const new_func = new_func_val.castTag(.function).?.data; | 6103 | const new_func = new_func_val.castTag(.function).?.data; |
| 6098 | errdefer new_func.deinit(gpa); | 6104 | errdefer new_func.deinit(gpa); |
| 6099 | assert(new_func == new_module_func); | 6105 | assert(new_func == new_module_func); |
| ... | @@ -6195,7 +6201,7 @@ fn instantiateGenericCall( | ... | @@ -6195,7 +6201,7 @@ fn instantiateGenericCall( |
| 6195 | const callee_inst = try sema.analyzeDeclVal(block, func_src, callee.owner_decl); | 6201 | const callee_inst = try sema.analyzeDeclVal(block, func_src, callee.owner_decl); |
| 6196 | | 6202 | |
| 6197 | // Make a runtime call to the new function, making sure to omit the comptime args. | 6203 | // Make a runtime call to the new function, making sure to omit the comptime args. |
| 6198 | try sema.requireRuntimeBlock(block, call_src); | 6204 | try sema.requireFunctionBlock(block, call_src); |
| 6199 | | 6205 | |
| 6200 | const comptime_args = callee.comptime_args.?; | 6206 | const comptime_args = callee.comptime_args.?; |
| 6201 | const new_fn_info = mod.declPtr(callee.owner_decl).ty.fnInfo(); | 6207 | const new_fn_info = mod.declPtr(callee.owner_decl).ty.fnInfo(); |
| ... | @@ -6314,7 +6320,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -6314,7 +6320,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6314 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6320 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6315 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6321 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6316 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 6322 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 6317 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.u32); | 6323 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime known"); |
| 6318 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); | 6324 | const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs); |
| 6319 | try sema.checkVectorElemType(block, elem_type_src, elem_type); | 6325 | try sema.checkVectorElemType(block, elem_type_src, elem_type); |
| 6320 | const vector_type = try Type.Tag.vector.create(sema.arena, .{ | 6326 | const vector_type = try Type.Tag.vector.create(sema.arena, .{ |
| ... | @@ -6332,7 +6338,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -6332,7 +6338,7 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6332 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 6338 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 6333 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 6339 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 6334 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 6340 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 6335 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize); | 6341 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, "array length must be comptime known"); |
| 6336 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | 6342 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); |
| 6337 | const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod); | 6343 | const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod); |
| 6338 | | 6344 | |
| ... | @@ -6348,11 +6354,11 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -6348,11 +6354,11 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 6348 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 6354 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; |
| 6349 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; | 6355 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; |
| 6350 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 6356 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 6351 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize); | 6357 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, "array length must be comptime known"); |
| 6352 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); | 6358 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); |
| 6353 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); | 6359 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 6354 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); | 6360 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 6355 | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel); | 6361 | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, "array sentinel value must be comptime known"); |
| 6356 | const array_ty = try Type.array(sema.arena, len, sentinel_val, elem_type, sema.mod); | 6362 | const array_ty = try Type.array(sema.arena, len, sentinel_val, elem_type, sema.mod); |
| 6357 | | 6363 | |
| 6358 | return sema.addType(array_ty); | 6364 | return sema.addType(array_ty); |
| ... | @@ -6452,7 +6458,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -6452,7 +6458,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 6452 | } | 6458 | } |
| 6453 | } | 6459 | } |
| 6454 | | 6460 | |
| 6455 | try sema.requireRuntimeBlock(block, src); | 6461 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 6456 | return block.addBitCast(result_ty, operand); | 6462 | return block.addBitCast(result_ty, operand); |
| 6457 | } | 6463 | } |
| 6458 | | 6464 | |
| ... | @@ -6478,7 +6484,7 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -6478,7 +6484,7 @@ fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 6478 | }; | 6484 | }; |
| 6479 | return sema.addConstant(Type.anyerror, Value.initPayload(&payload.base)); | 6485 | return sema.addConstant(Type.anyerror, Value.initPayload(&payload.base)); |
| 6480 | } | 6486 | } |
| 6481 | try sema.requireRuntimeBlock(block, src); | 6487 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 6482 | if (block.wantSafety()) { | 6488 | if (block.wantSafety()) { |
| 6483 | const is_lt_len = try block.addUnOp(.cmp_lt_errors_len, operand); | 6489 | const is_lt_len = try block.addUnOp(.cmp_lt_errors_len, operand); |
| 6484 | try sema.addSafetyCheck(block, is_lt_len, .invalid_error_code); | 6490 | try sema.addSafetyCheck(block, is_lt_len, .invalid_error_code); |
| ... | @@ -6598,7 +6604,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -6598,7 +6604,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6598 | return sema.addConstant(int_tag_ty, try val.copy(sema.arena)); | 6604 | return sema.addConstant(int_tag_ty, try val.copy(sema.arena)); |
| 6599 | } | 6605 | } |
| 6600 | | 6606 | |
| 6601 | try sema.requireRuntimeBlock(block, src); | 6607 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 6602 | return block.addBitCast(int_tag_ty, enum_tag); | 6608 | return block.addBitCast(int_tag_ty, enum_tag); |
| 6603 | } | 6609 | } |
| 6604 | | 6610 | |
| ... | @@ -6645,7 +6651,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -6645,7 +6651,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6645 | return sema.addConstant(dest_ty, int_val); | 6651 | return sema.addConstant(dest_ty, int_val); |
| 6646 | } | 6652 | } |
| 6647 | | 6653 | |
| 6648 | try sema.requireRuntimeBlock(block, src); | 6654 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 6649 | // TODO insert safety check to make sure the value matches an enum value | 6655 | // TODO insert safety check to make sure the value matches an enum value |
| 6650 | return block.addTyOp(.intcast, dest_ty, operand); | 6656 | return block.addTyOp(.intcast, dest_ty, operand); |
| 6651 | } | 6657 | } |
| ... | @@ -6696,7 +6702,7 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -6696,7 +6702,7 @@ fn analyzeOptionalPayloadPtr( |
| 6696 | // If the pointer resulting from this function was stored at comptime, | 6702 | // If the pointer resulting from this function was stored at comptime, |
| 6697 | // the optional non-null bit would be set that way. But in this case, | 6703 | // the optional non-null bit would be set that way. But in this case, |
| 6698 | // we need to emit a runtime instruction to do it. | 6704 | // we need to emit a runtime instruction to do it. |
| 6699 | try sema.requireRuntimeBlock(block, src); | 6705 | try sema.requireFunctionBlock(block, src); |
| 6700 | _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr); | 6706 | _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr); |
| 6701 | } | 6707 | } |
| 6702 | return sema.addConstant( | 6708 | return sema.addConstant( |
| ... | @@ -6722,7 +6728,7 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -6722,7 +6728,7 @@ fn analyzeOptionalPayloadPtr( |
| 6722 | } | 6728 | } |
| 6723 | } | 6729 | } |
| 6724 | | 6730 | |
| 6725 | try sema.requireRuntimeBlock(block, src); | 6731 | try sema.requireRuntimeBlock(block, src, null); |
| 6726 | if (safety_check and block.wantSafety()) { | 6732 | if (safety_check and block.wantSafety()) { |
| 6727 | const is_non_null = try block.addUnOp(.is_non_null_ptr, optional_ptr); | 6733 | const is_non_null = try block.addUnOp(.is_non_null_ptr, optional_ptr); |
| 6728 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); | 6734 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); |
| ... | @@ -6778,7 +6784,7 @@ fn zirOptionalPayload( | ... | @@ -6778,7 +6784,7 @@ fn zirOptionalPayload( |
| 6778 | return sema.addConstant(result_ty, val); | 6784 | return sema.addConstant(result_ty, val); |
| 6779 | } | 6785 | } |
| 6780 | | 6786 | |
| 6781 | try sema.requireRuntimeBlock(block, src); | 6787 | try sema.requireRuntimeBlock(block, src, null); |
| 6782 | if (safety_check and block.wantSafety()) { | 6788 | if (safety_check and block.wantSafety()) { |
| 6783 | const is_non_null = try block.addUnOp(.is_non_null, operand); | 6789 | const is_non_null = try block.addUnOp(.is_non_null, operand); |
| 6784 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); | 6790 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); |
| ... | @@ -6827,7 +6833,7 @@ fn analyzeErrUnionPayload( | ... | @@ -6827,7 +6833,7 @@ fn analyzeErrUnionPayload( |
| 6827 | return sema.addConstant(payload_ty, data); | 6833 | return sema.addConstant(payload_ty, data); |
| 6828 | } | 6834 | } |
| 6829 | | 6835 | |
| 6830 | try sema.requireRuntimeBlock(block, src); | 6836 | try sema.requireRuntimeBlock(block, src, null); |
| 6831 | | 6837 | |
| 6832 | // If the error set has no fields then no safety check is needed. | 6838 | // If the error set has no fields then no safety check is needed. |
| 6833 | if (safety_check and block.wantSafety() and | 6839 | if (safety_check and block.wantSafety() and |
| ... | @@ -6887,7 +6893,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -6887,7 +6893,7 @@ fn analyzeErrUnionPayloadPtr( |
| 6887 | // If the pointer resulting from this function was stored at comptime, | 6893 | // If the pointer resulting from this function was stored at comptime, |
| 6888 | // the error union error code would be set that way. But in this case, | 6894 | // the error union error code would be set that way. But in this case, |
| 6889 | // we need to emit a runtime instruction to do it. | 6895 | // we need to emit a runtime instruction to do it. |
| 6890 | try sema.requireRuntimeBlock(block, src); | 6896 | try sema.requireRuntimeBlock(block, src, null); |
| 6891 | _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand); | 6897 | _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand); |
| 6892 | } | 6898 | } |
| 6893 | return sema.addConstant( | 6899 | return sema.addConstant( |
| ... | @@ -6913,7 +6919,7 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -6913,7 +6919,7 @@ fn analyzeErrUnionPayloadPtr( |
| 6913 | } | 6919 | } |
| 6914 | } | 6920 | } |
| 6915 | | 6921 | |
| 6916 | try sema.requireRuntimeBlock(block, src); | 6922 | try sema.requireRuntimeBlock(block, src, null); |
| 6917 | | 6923 | |
| 6918 | // If the error set has no fields then no safety check is needed. | 6924 | // If the error set has no fields then no safety check is needed. |
| 6919 | if (safety_check and block.wantSafety() and | 6925 | if (safety_check and block.wantSafety() and |
| ... | @@ -6951,7 +6957,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -6951,7 +6957,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 6951 | return sema.addConstant(result_ty, val); | 6957 | return sema.addConstant(result_ty, val); |
| 6952 | } | 6958 | } |
| 6953 | | 6959 | |
| 6954 | try sema.requireRuntimeBlock(block, src); | 6960 | try sema.requireRuntimeBlock(block, src, null); |
| 6955 | return block.addTyOp(.unwrap_errunion_err, result_ty, operand); | 6961 | return block.addTyOp(.unwrap_errunion_err, result_ty, operand); |
| 6956 | } | 6962 | } |
| 6957 | | 6963 | |
| ... | @@ -6981,7 +6987,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -6981,7 +6987,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 6981 | } | 6987 | } |
| 6982 | } | 6988 | } |
| 6983 | | 6989 | |
| 6984 | try sema.requireRuntimeBlock(block, src); | 6990 | try sema.requireRuntimeBlock(block, src, null); |
| 6985 | return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand); | 6991 | return block.addTyOp(.unwrap_errunion_err_ptr, result_ty, operand); |
| 6986 | } | 6992 | } |
| 6987 | | 6993 | |
| ... | @@ -7037,7 +7043,7 @@ fn zirFunc( | ... | @@ -7037,7 +7043,7 @@ fn zirFunc( |
| 7037 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; | 7043 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 7038 | extra_index += ret_ty_body.len; | 7044 | extra_index += ret_ty_body.len; |
| 7039 | | 7045 | |
| 7040 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type); | 7046 | const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, "return type must be comptime known"); |
| 7041 | var buffer: Value.ToTypeBuffer = undefined; | 7047 | var buffer: Value.ToTypeBuffer = undefined; |
| 7042 | break :blk try ret_ty_val.toType(&buffer).copy(sema.arena); | 7048 | break :blk try ret_ty_val.toType(&buffer).copy(sema.arena); |
| 7043 | }, | 7049 | }, |
| ... | @@ -7085,6 +7091,7 @@ fn resolveGenericBody( | ... | @@ -7085,6 +7091,7 @@ fn resolveGenericBody( |
| 7085 | body: []const Zir.Inst.Index, | 7091 | body: []const Zir.Inst.Index, |
| 7086 | func_inst: Zir.Inst.Index, | 7092 | func_inst: Zir.Inst.Index, |
| 7087 | dest_ty: Type, | 7093 | dest_ty: Type, |
| | 7094 | reason: []const u8, |
| 7088 | ) !Value { | 7095 | ) !Value { |
| 7089 | assert(body.len != 0); | 7096 | assert(body.len != 0); |
| 7090 | | 7097 | |
| ... | @@ -7098,7 +7105,7 @@ fn resolveGenericBody( | ... | @@ -7098,7 +7105,7 @@ fn resolveGenericBody( |
| 7098 | } | 7105 | } |
| 7099 | const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err; | 7106 | const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err; |
| 7100 | const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err; | 7107 | const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err; |
| 7101 | const val = sema.resolveConstValue(block, src, result) catch |err| break :err err; | 7108 | const val = sema.resolveConstValue(block, src, result, reason) catch |err| break :err err; |
| 7102 | return val; | 7109 | return val; |
| 7103 | }; | 7110 | }; |
| 7104 | switch (err) { | 7111 | switch (err) { |
| ... | @@ -7629,7 +7636,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -7629,7 +7636,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 7629 | if (try sema.resolveMaybeUndefVal(block, ptr_src, ptr)) |ptr_val| { | 7636 | if (try sema.resolveMaybeUndefVal(block, ptr_src, ptr)) |ptr_val| { |
| 7630 | return sema.addConstant(Type.usize, ptr_val); | 7637 | return sema.addConstant(Type.usize, ptr_val); |
| 7631 | } | 7638 | } |
| 7632 | try sema.requireRuntimeBlock(block, ptr_src); | 7639 | try sema.requireRuntimeBlock(block, ptr_src, ptr_src); |
| 7633 | return block.addUnOp(.ptrtoint, ptr); | 7640 | return block.addUnOp(.ptrtoint, ptr); |
| 7634 | } | 7641 | } |
| 7635 | | 7642 | |
| ... | @@ -7681,7 +7688,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -7681,7 +7688,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 7681 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 7688 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 7682 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 7689 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 7683 | const object = try sema.resolveInst(extra.lhs); | 7690 | const object = try sema.resolveInst(extra.lhs); |
| 7684 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name); | 7691 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name, "field name must be comptime known"); |
| 7685 | return sema.fieldVal(block, src, object, field_name, field_name_src); | 7692 | return sema.fieldVal(block, src, object, field_name, field_name_src); |
| 7686 | } | 7693 | } |
| 7687 | | 7694 | |
| ... | @@ -7694,7 +7701,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -7694,7 +7701,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 7694 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 7701 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 7695 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 7702 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 7696 | const object_ptr = try sema.resolveInst(extra.lhs); | 7703 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 7697 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name); | 7704 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name, "field name must be comptime known"); |
| 7698 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); | 7705 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src); |
| 7699 | } | 7706 | } |
| 7700 | | 7707 | |
| ... | @@ -7706,7 +7713,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Block, extended: Zir.Inst.Extended | ... | @@ -7706,7 +7713,7 @@ fn zirFieldCallBindNamed(sema: *Sema, block: *Block, extended: Zir.Inst.Extended |
| 7706 | const src = LazySrcLoc.nodeOffset(extra.node); | 7713 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 7707 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 7714 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 7708 | const object_ptr = try sema.resolveInst(extra.lhs); | 7715 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 7709 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name); | 7716 | const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name, "field name must be comptime known"); |
| 7710 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); | 7717 | return sema.fieldCallBind(block, src, object_ptr, field_name, field_name_src); |
| 7711 | } | 7718 | } |
| 7712 | | 7719 | |
| ... | @@ -7722,12 +7729,13 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -7722,12 +7729,13 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7722 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); | 7729 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 7723 | const operand = try sema.resolveInst(extra.rhs); | 7730 | const operand = try sema.resolveInst(extra.rhs); |
| 7724 | | 7731 | |
| 7725 | return sema.intCast(block, dest_ty, dest_ty_src, operand, operand_src, true); | 7732 | return sema.intCast(block, inst_data.src(), dest_ty, dest_ty_src, operand, operand_src, true); |
| 7726 | } | 7733 | } |
| 7727 | | 7734 | |
| 7728 | fn intCast( | 7735 | fn intCast( |
| 7729 | sema: *Sema, | 7736 | sema: *Sema, |
| 7730 | block: *Block, | 7737 | block: *Block, |
| | 7738 | src: LazySrcLoc, |
| 7731 | dest_ty: Type, | 7739 | dest_ty: Type, |
| 7732 | dest_ty_src: LazySrcLoc, | 7740 | dest_ty_src: LazySrcLoc, |
| 7733 | operand: Air.Inst.Ref, | 7741 | operand: Air.Inst.Ref, |
| ... | @@ -7750,7 +7758,7 @@ fn intCast( | ... | @@ -7750,7 +7758,7 @@ fn intCast( |
| 7750 | if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| { | 7758 | if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| { |
| 7751 | // requirement: intCast(u0, input) iff input == 0 | 7759 | // requirement: intCast(u0, input) iff input == 0 |
| 7752 | if (runtime_safety and block.wantSafety()) { | 7760 | if (runtime_safety and block.wantSafety()) { |
| 7753 | try sema.requireRuntimeBlock(block, operand_src); | 7761 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 7754 | const target = sema.mod.getTarget(); | 7762 | const target = sema.mod.getTarget(); |
| 7755 | const wanted_info = dest_scalar_ty.intInfo(target); | 7763 | const wanted_info = dest_scalar_ty.intInfo(target); |
| 7756 | const wanted_bits = wanted_info.bits; | 7764 | const wanted_bits = wanted_info.bits; |
| ... | @@ -7765,7 +7773,7 @@ fn intCast( | ... | @@ -7765,7 +7773,7 @@ fn intCast( |
| 7765 | return sema.addConstant(dest_ty, opv); | 7773 | return sema.addConstant(dest_ty, opv); |
| 7766 | } | 7774 | } |
| 7767 | | 7775 | |
| 7768 | try sema.requireRuntimeBlock(block, operand_src); | 7776 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 7769 | if (runtime_safety and block.wantSafety()) { | 7777 | if (runtime_safety and block.wantSafety()) { |
| 7770 | const target = sema.mod.getTarget(); | 7778 | const target = sema.mod.getTarget(); |
| 7771 | const actual_info = operand_scalar_ty.intInfo(target); | 7779 | const actual_info = operand_scalar_ty.intInfo(target); |
| ... | @@ -7972,7 +7980,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -7972,7 +7980,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 7972 | if (dst_bits >= src_bits) { | 7980 | if (dst_bits >= src_bits) { |
| 7973 | return sema.coerce(block, dest_ty, operand, operand_src); | 7981 | return sema.coerce(block, dest_ty, operand, operand_src); |
| 7974 | } | 7982 | } |
| 7975 | try sema.requireRuntimeBlock(block, operand_src); | 7983 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| 7976 | return block.addTyOp(.fptrunc, dest_ty, operand); | 7984 | return block.addTyOp(.fptrunc, dest_ty, operand); |
| 7977 | } | 7985 | } |
| 7978 | | 7986 | |
| ... | @@ -8141,7 +8149,7 @@ fn zirSwitchCapture( | ... | @@ -8141,7 +8149,7 @@ fn zirSwitchCapture( |
| 8141 | | 8149 | |
| 8142 | const first_item = try sema.resolveInst(items[0]); | 8150 | const first_item = try sema.resolveInst(items[0]); |
| 8143 | // Previous switch validation ensured this will succeed | 8151 | // Previous switch validation ensured this will succeed |
| 8144 | const first_item_val = sema.resolveConstValue(block, .unneeded, first_item) catch unreachable; | 8152 | const first_item_val = sema.resolveConstValue(block, .unneeded, first_item, undefined) catch unreachable; |
| 8145 | | 8153 | |
| 8146 | const first_field_index = @intCast(u32, enum_ty.enumTagFieldIndex(first_item_val, sema.mod).?); | 8154 | const first_field_index = @intCast(u32, enum_ty.enumTagFieldIndex(first_item_val, sema.mod).?); |
| 8147 | const first_field = union_obj.fields.values()[first_field_index]; | 8155 | const first_field = union_obj.fields.values()[first_field_index]; |
| ... | @@ -8149,7 +8157,7 @@ fn zirSwitchCapture( | ... | @@ -8149,7 +8157,7 @@ fn zirSwitchCapture( |
| 8149 | for (items[1..]) |item| { | 8157 | for (items[1..]) |item| { |
| 8150 | const item_ref = try sema.resolveInst(item); | 8158 | const item_ref = try sema.resolveInst(item); |
| 8151 | // Previous switch validation ensured this will succeed | 8159 | // Previous switch validation ensured this will succeed |
| 8152 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable; | 8160 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, undefined) catch unreachable; |
| 8153 | | 8161 | |
| 8154 | const field_index = enum_ty.enumTagFieldIndex(item_val, sema.mod).?; | 8162 | const field_index = enum_ty.enumTagFieldIndex(item_val, sema.mod).?; |
| 8155 | const field = union_obj.fields.values()[field_index]; | 8163 | const field = union_obj.fields.values()[field_index]; |
| ... | @@ -8186,7 +8194,7 @@ fn zirSwitchCapture( | ... | @@ -8186,7 +8194,7 @@ fn zirSwitchCapture( |
| 8186 | }), | 8194 | }), |
| 8187 | ); | 8195 | ); |
| 8188 | } | 8196 | } |
| 8189 | try sema.requireRuntimeBlock(block, operand_src); | 8197 | try sema.requireRuntimeBlock(block, operand_src, null); |
| 8190 | return block.addStructFieldPtr(operand_ptr, first_field_index, field_ty_ptr); | 8198 | return block.addStructFieldPtr(operand_ptr, first_field_index, field_ty_ptr); |
| 8191 | } | 8199 | } |
| 8192 | | 8200 | |
| ... | @@ -8196,7 +8204,7 @@ fn zirSwitchCapture( | ... | @@ -8196,7 +8204,7 @@ fn zirSwitchCapture( |
| 8196 | operand_val.castTag(.@"union").?.data.val, | 8204 | operand_val.castTag(.@"union").?.data.val, |
| 8197 | ); | 8205 | ); |
| 8198 | } | 8206 | } |
| 8199 | try sema.requireRuntimeBlock(block, operand_src); | 8207 | try sema.requireRuntimeBlock(block, operand_src, null); |
| 8200 | return block.addStructFieldVal(operand, first_field_index, first_field.ty); | 8208 | return block.addStructFieldVal(operand, first_field_index, first_field.ty); |
| 8201 | }, | 8209 | }, |
| 8202 | .ErrorSet => { | 8210 | .ErrorSet => { |
| ... | @@ -8206,7 +8214,7 @@ fn zirSwitchCapture( | ... | @@ -8206,7 +8214,7 @@ fn zirSwitchCapture( |
| 8206 | for (items) |item| { | 8214 | for (items) |item| { |
| 8207 | const item_ref = try sema.resolveInst(item); | 8215 | const item_ref = try sema.resolveInst(item); |
| 8208 | // Previous switch validation ensured this will succeed | 8216 | // Previous switch validation ensured this will succeed |
| 8209 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable; | 8217 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, undefined) catch unreachable; |
| 8210 | names.putAssumeCapacityNoClobber( | 8218 | names.putAssumeCapacityNoClobber( |
| 8211 | item_val.getError().?, | 8219 | item_val.getError().?, |
| 8212 | {}, | 8220 | {}, |
| ... | @@ -8220,7 +8228,7 @@ fn zirSwitchCapture( | ... | @@ -8220,7 +8228,7 @@ fn zirSwitchCapture( |
| 8220 | } else { | 8228 | } else { |
| 8221 | const item_ref = try sema.resolveInst(items[0]); | 8229 | const item_ref = try sema.resolveInst(items[0]); |
| 8222 | // Previous switch validation ensured this will succeed | 8230 | // Previous switch validation ensured this will succeed |
| 8223 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref) catch unreachable; | 8231 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, undefined) catch unreachable; |
| 8224 | | 8232 | |
| 8225 | const item_ty = try Type.Tag.error_set_single.create(sema.arena, item_val.getError().?); | 8233 | const item_ty = try Type.Tag.error_set_single.create(sema.arena, item_val.getError().?); |
| 8226 | return sema.bitCast(block, item_ty, operand, operand_src); | 8234 | return sema.bitCast(block, item_ty, operand, operand_src); |
| ... | @@ -8924,7 +8932,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8924,7 +8932,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8924 | | 8932 | |
| 8925 | const item = try sema.resolveInst(item_ref); | 8933 | const item = try sema.resolveInst(item_ref); |
| 8926 | // Validation above ensured these will succeed. | 8934 | // Validation above ensured these will succeed. |
| 8927 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable; | 8935 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 8928 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 8936 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 8929 | return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); | 8937 | return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); |
| 8930 | } | 8938 | } |
| ... | @@ -8946,7 +8954,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8946,7 +8954,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8946 | for (items) |item_ref| { | 8954 | for (items) |item_ref| { |
| 8947 | const item = try sema.resolveInst(item_ref); | 8955 | const item = try sema.resolveInst(item_ref); |
| 8948 | // Validation above ensured these will succeed. | 8956 | // Validation above ensured these will succeed. |
| 8949 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item) catch unreachable; | 8957 | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 8950 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 8958 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 8951 | return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); | 8959 | return sema.resolveBlockBody(block, src, &child_block, body, inst, merges); |
| 8952 | } | 8960 | } |
| ... | @@ -8960,8 +8968,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8960,8 +8968,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8960 | extra_index += 1; | 8968 | extra_index += 1; |
| 8961 | | 8969 | |
| 8962 | // Validation above ensured these will succeed. | 8970 | // Validation above ensured these will succeed. |
| 8963 | const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first) catch unreachable; | 8971 | const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, undefined) catch unreachable; |
| 8964 | const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last) catch unreachable; | 8972 | const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last, undefined) catch unreachable; |
| 8965 | if ((try sema.compare(block, src, operand_val, .gte, first_tv.val, operand_ty)) and | 8973 | if ((try sema.compare(block, src, operand_val, .gte, first_tv.val, operand_ty)) and |
| 8966 | (try sema.compare(block, src, operand_val, .lte, last_tv.val, operand_ty))) | 8974 | (try sema.compare(block, src, operand_val, .lte, last_tv.val, operand_ty))) |
| 8967 | { | 8975 | { |
| ... | @@ -8982,7 +8990,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8982,7 +8990,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8982 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); | 8990 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); |
| 8983 | } | 8991 | } |
| 8984 | | 8992 | |
| 8985 | try sema.requireRuntimeBlock(block, src); | 8993 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 8986 | | 8994 | |
| 8987 | const estimated_cases_extra = (scalar_cases_len + multi_cases_len) * | 8995 | const estimated_cases_extra = (scalar_cases_len + multi_cases_len) * |
| 8988 | @typeInfo(Air.SwitchBr.Case).Struct.fields.len + 2; | 8996 | @typeInfo(Air.SwitchBr.Case).Struct.fields.len + 2; |
| ... | @@ -9271,14 +9279,14 @@ fn resolveSwitchItemVal( | ... | @@ -9271,14 +9279,14 @@ fn resolveSwitchItemVal( |
| 9271 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. | 9279 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. |
| 9272 | // Only if we know for sure we need to report a compile error do we resolve the | 9280 | // Only if we know for sure we need to report a compile error do we resolve the |
| 9273 | // full source locations. | 9281 | // full source locations. |
| 9274 | if (sema.resolveConstValue(block, .unneeded, item)) |val| { | 9282 | if (sema.resolveConstValue(block, .unneeded, item, undefined)) |val| { |
| 9275 | return TypedValue{ .ty = item_ty, .val = val }; | 9283 | return TypedValue{ .ty = item_ty, .val = val }; |
| 9276 | } else |err| switch (err) { | 9284 | } else |err| switch (err) { |
| 9277 | error.NeededSourceLocation => { | 9285 | error.NeededSourceLocation => { |
| 9278 | const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 9286 | const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 9279 | return TypedValue{ | 9287 | return TypedValue{ |
| 9280 | .ty = item_ty, | 9288 | .ty = item_ty, |
| 9281 | .val = try sema.resolveConstValue(block, src, item), | 9289 | .val = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime known"), |
| 9282 | }; | 9290 | }; |
| 9283 | }, | 9291 | }, |
| 9284 | else => |e| return e, | 9292 | else => |e| return e, |
| ... | @@ -9464,7 +9472,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -9464,7 +9472,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9464 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9472 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9465 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9473 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9466 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); | 9474 | const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 9467 | const field_name = try sema.resolveConstString(block, name_src, extra.rhs); | 9475 | const field_name = try sema.resolveConstString(block, name_src, extra.rhs, "field name must be comptime known"); |
| 9468 | const ty = try sema.resolveTypeFields(block, ty_src, unresolved_ty); | 9476 | const ty = try sema.resolveTypeFields(block, ty_src, unresolved_ty); |
| 9469 | | 9477 | |
| 9470 | const has_field = hf: { | 9478 | const has_field = hf: { |
| ... | @@ -9506,7 +9514,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9506,7 +9514,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9506 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9514 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9507 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 9515 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 9508 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 9516 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 9509 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); | 9517 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "decl name must be comptime known"); |
| 9510 | | 9518 | |
| 9511 | try checkNamespaceType(sema, block, lhs_src, container_type); | 9519 | try checkNamespaceType(sema, block, lhs_src, container_type); |
| 9512 | | 9520 | |
| ... | @@ -9553,7 +9561,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -9553,7 +9561,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9553 | const mod = sema.mod; | 9561 | const mod = sema.mod; |
| 9554 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9562 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9555 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 9563 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 9556 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand); | 9564 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime known"); |
| 9557 | | 9565 | |
| 9558 | const embed_file = mod.embedFile(block.getFileScope(), name) catch |err| switch (err) { | 9566 | const embed_file = mod.embedFile(block.getFileScope(), name) catch |err| switch (err) { |
| 9559 | error.ImportOutsidePkgPath => { | 9567 | error.ImportOutsidePkgPath => { |
| ... | @@ -9707,13 +9715,13 @@ fn zirShl( | ... | @@ -9707,13 +9715,13 @@ fn zirShl( |
| 9707 | try lhs_ty.maxInt(sema.arena, target), | 9715 | try lhs_ty.maxInt(sema.arena, target), |
| 9708 | ); | 9716 | ); |
| 9709 | const rhs_limited = try sema.analyzeMinMax(block, rhs_src, rhs, max_int, .min, rhs_src, rhs_src); | 9717 | const rhs_limited = try sema.analyzeMinMax(block, rhs_src, rhs, max_int, .min, rhs_src, rhs_src); |
| 9710 | break :rhs try sema.intCast(block, lhs_ty, rhs_src, rhs_limited, rhs_src, false); | 9718 | break :rhs try sema.intCast(block, src, lhs_ty, rhs_src, rhs_limited, rhs_src, false); |
| 9711 | } else { | 9719 | } else { |
| 9712 | break :rhs rhs; | 9720 | break :rhs rhs; |
| 9713 | } | 9721 | } |
| 9714 | } else rhs; | 9722 | } else rhs; |
| 9715 | | 9723 | |
| 9716 | try sema.requireRuntimeBlock(block, runtime_src); | 9724 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 9717 | if (block.wantSafety()) { | 9725 | if (block.wantSafety()) { |
| 9718 | const maybe_op_ov: ?Air.Inst.Tag = switch (air_tag) { | 9726 | const maybe_op_ov: ?Air.Inst.Tag = switch (air_tag) { |
| 9719 | .shl_exact => .shl_with_overflow, | 9727 | .shl_exact => .shl_with_overflow, |
| ... | @@ -9824,7 +9832,7 @@ fn zirShr( | ... | @@ -9824,7 +9832,7 @@ fn zirShr( |
| 9824 | } | 9832 | } |
| 9825 | } else rhs_src; | 9833 | } else rhs_src; |
| 9826 | | 9834 | |
| 9827 | try sema.requireRuntimeBlock(block, runtime_src); | 9835 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 9828 | return block.addBinOp(air_tag, lhs, rhs); | 9836 | return block.addBinOp(air_tag, lhs, rhs); |
| 9829 | } | 9837 | } |
| 9830 | | 9838 | |
| ... | @@ -9883,7 +9891,7 @@ fn zirBitwise( | ... | @@ -9883,7 +9891,7 @@ fn zirBitwise( |
| 9883 | } | 9891 | } |
| 9884 | }; | 9892 | }; |
| 9885 | | 9893 | |
| 9886 | try sema.requireRuntimeBlock(block, runtime_src); | 9894 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 9887 | return block.addBinOp(air_tag, casted_lhs, casted_rhs); | 9895 | return block.addBinOp(air_tag, casted_lhs, casted_rhs); |
| 9888 | } | 9896 | } |
| 9889 | | 9897 | |
| ... | @@ -9927,7 +9935,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -9927,7 +9935,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 9927 | } | 9935 | } |
| 9928 | } | 9936 | } |
| 9929 | | 9937 | |
| 9930 | try sema.requireRuntimeBlock(block, src); | 9938 | try sema.requireRuntimeBlock(block, src, null); |
| 9931 | return block.addTyOp(.not, operand_type, operand); | 9939 | return block.addTyOp(.not, operand_type, operand); |
| 9932 | } | 9940 | } |
| 9933 | | 9941 | |
| ... | @@ -9940,6 +9948,7 @@ fn analyzeTupleCat( | ... | @@ -9940,6 +9948,7 @@ fn analyzeTupleCat( |
| 9940 | ) CompileError!Air.Inst.Ref { | 9948 | ) CompileError!Air.Inst.Ref { |
| 9941 | const lhs_ty = sema.typeOf(lhs); | 9949 | const lhs_ty = sema.typeOf(lhs); |
| 9942 | const rhs_ty = sema.typeOf(rhs); | 9950 | const rhs_ty = sema.typeOf(rhs); |
| | 9951 | const src = LazySrcLoc.nodeOffset(src_node); |
| 9943 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = src_node }; | 9952 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = src_node }; |
| 9944 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; | 9953 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; |
| 9945 | | 9954 | |
| ... | @@ -9987,7 +9996,7 @@ fn analyzeTupleCat( | ... | @@ -9987,7 +9996,7 @@ fn analyzeTupleCat( |
| 9987 | return sema.addConstant(tuple_ty, tuple_val); | 9996 | return sema.addConstant(tuple_ty, tuple_val); |
| 9988 | }; | 9997 | }; |
| 9989 | | 9998 | |
| 9990 | try sema.requireRuntimeBlock(block, runtime_src); | 9999 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 9991 | | 10000 | |
| 9992 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 10001 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 9993 | for (lhs_tuple.types) |_, i| { | 10002 | for (lhs_tuple.types) |_, i| { |
| ... | @@ -10050,8 +10059,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10050,8 +10059,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10050 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); | 10059 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); |
| 10051 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 10060 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 10052 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 10061 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 10053 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted); | 10062 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime known"); |
| 10054 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted); | 10063 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime known"); |
| 10055 | if (try sema.valuesEqual(block, src, lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { | 10064 | if (try sema.valuesEqual(block, src, lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| 10056 | break :s lhs_sent_casted_val; | 10065 | break :s lhs_sent_casted_val; |
| 10057 | } else { | 10066 | } else { |
| ... | @@ -10059,14 +10068,14 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10059,14 +10068,14 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10059 | } | 10068 | } |
| 10060 | } else { | 10069 | } else { |
| 10061 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); | 10070 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 10062 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted); | 10071 | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime known"); |
| 10063 | break :s lhs_sent_casted_val; | 10072 | break :s lhs_sent_casted_val; |
| 10064 | } | 10073 | } |
| 10065 | } else { | 10074 | } else { |
| 10066 | if (rhs_info.sentinel) |rhs_sent_val| { | 10075 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 10067 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); | 10076 | const rhs_sent = try sema.addConstant(rhs_info.elem_type, rhs_sent_val); |
| 10068 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); | 10077 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 10069 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted); | 10078 | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime known"); |
| 10070 | break :s rhs_sent_casted_val; | 10079 | break :s rhs_sent_casted_val; |
| 10071 | } else { | 10080 | } else { |
| 10072 | break :s null; | 10081 | break :s null; |
| ... | @@ -10121,7 +10130,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10121,7 +10130,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10121 | } else break :rs rhs_src; | 10130 | } else break :rs rhs_src; |
| 10122 | } else lhs_src; | 10131 | } else lhs_src; |
| 10123 | | 10132 | |
| 10124 | try sema.requireRuntimeBlock(block, runtime_src); | 10133 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 10125 | | 10134 | |
| 10126 | if (ptr_addrspace) |ptr_as| { | 10135 | if (ptr_addrspace) |ptr_as| { |
| 10127 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 10136 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | @@ -10187,7 +10196,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins | ... | @@ -10187,7 +10196,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 10187 | // has a sentinel, and this code should compute the length based | 10196 | // has a sentinel, and this code should compute the length based |
| 10188 | // on the sentinel value. | 10197 | // on the sentinel value. |
| 10189 | .Slice, .Many => { | 10198 | .Slice, .Many => { |
| 10190 | const val = try sema.resolveConstValue(block, src, operand); | 10199 | const val = try sema.resolveConstValue(block, src, operand, "slice value being concatenated must be comptime known"); |
| 10191 | return Type.ArrayInfo{ | 10200 | return Type.ArrayInfo{ |
| 10192 | .elem_type = ptr_info.pointee_type, | 10201 | .elem_type = ptr_info.pointee_type, |
| 10193 | .sentinel = ptr_info.sentinel, | 10202 | .sentinel = ptr_info.sentinel, |
| ... | @@ -10216,6 +10225,7 @@ fn analyzeTupleMul( | ... | @@ -10216,6 +10225,7 @@ fn analyzeTupleMul( |
| 10216 | ) CompileError!Air.Inst.Ref { | 10225 | ) CompileError!Air.Inst.Ref { |
| 10217 | const operand_ty = sema.typeOf(operand); | 10226 | const operand_ty = sema.typeOf(operand); |
| 10218 | const operand_tuple = operand_ty.tupleFields(); | 10227 | const operand_tuple = operand_ty.tupleFields(); |
| | 10228 | const src = LazySrcLoc.nodeOffset(src_node); |
| 10219 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = src_node }; | 10229 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = src_node }; |
| 10220 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; | 10230 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; |
| 10221 | | 10231 | |
| ... | @@ -10259,7 +10269,7 @@ fn analyzeTupleMul( | ... | @@ -10259,7 +10269,7 @@ fn analyzeTupleMul( |
| 10259 | return sema.addConstant(tuple_ty, tuple_val); | 10269 | return sema.addConstant(tuple_ty, tuple_val); |
| 10260 | }; | 10270 | }; |
| 10261 | | 10271 | |
| 10262 | try sema.requireRuntimeBlock(block, runtime_src); | 10272 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 10263 | | 10273 | |
| 10264 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 10274 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 10265 | for (operand_tuple.types) |_, i| { | 10275 | for (operand_tuple.types) |_, i| { |
| ... | @@ -10287,7 +10297,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10287,7 +10297,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10287 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 10297 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 10288 | | 10298 | |
| 10289 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | 10299 | // In `**` rhs must be comptime-known, but lhs can be runtime-known |
| 10290 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize); | 10300 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, "array multiplication factor must be comptime known"); |
| 10291 | | 10301 | |
| 10292 | if (lhs_ty.isTuple()) { | 10302 | if (lhs_ty.isTuple()) { |
| 10293 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor); | 10303 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor); |
| ... | @@ -10338,7 +10348,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10338,7 +10348,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10338 | return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null); | 10348 | return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null); |
| 10339 | } | 10349 | } |
| 10340 | | 10350 | |
| 10341 | try sema.requireRuntimeBlock(block, lhs_src); | 10351 | try sema.requireRuntimeBlock(block, src, lhs_src); |
| 10342 | | 10352 | |
| 10343 | if (ptr_addrspace) |ptr_as| { | 10353 | if (ptr_addrspace) |ptr_as| { |
| 10344 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 10354 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ |
| ... | @@ -10412,7 +10422,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -10412,7 +10422,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 10412 | const target = sema.mod.getTarget(); | 10422 | const target = sema.mod.getTarget(); |
| 10413 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target)); | 10423 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target)); |
| 10414 | } | 10424 | } |
| 10415 | try sema.requireRuntimeBlock(block, rhs_src); | 10425 | try sema.requireRuntimeBlock(block, src, null); |
| 10416 | return block.addUnOp(.neg, rhs); | 10426 | return block.addUnOp(.neg, rhs); |
| 10417 | } | 10427 | } |
| 10418 | | 10428 | |
| ... | @@ -10636,7 +10646,8 @@ fn zirOverflowArithmetic( | ... | @@ -10636,7 +10646,8 @@ fn zirOverflowArithmetic( |
| 10636 | else => unreachable, | 10646 | else => unreachable, |
| 10637 | }; | 10647 | }; |
| 10638 | | 10648 | |
| 10639 | try sema.requireRuntimeBlock(block, src); | 10649 | const runtime_src = if (maybe_lhs_val == null) lhs_src else rhs_src; |
| | 10650 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 10640 | | 10651 | |
| 10641 | const tuple = try block.addInst(.{ | 10652 | const tuple = try block.addInst(.{ |
| 10642 | .tag = air_tag, | 10653 | .tag = air_tag, |
| ... | @@ -11543,7 +11554,7 @@ fn analyzeArithmetic( | ... | @@ -11543,7 +11554,7 @@ fn analyzeArithmetic( |
| 11543 | } | 11554 | } |
| 11544 | }; | 11555 | }; |
| 11545 | | 11556 | |
| 11546 | try sema.requireRuntimeBlock(block, rs.src); | 11557 | try sema.requireRuntimeBlock(block, src, rs.src); |
| 11547 | if (block.wantSafety()) { | 11558 | if (block.wantSafety()) { |
| 11548 | if (scalar_tag == .Int) { | 11559 | if (scalar_tag == .Int) { |
| 11549 | const maybe_op_ov: ?Air.Inst.Tag = switch (rs.air_tag) { | 11560 | const maybe_op_ov: ?Air.Inst.Tag = switch (rs.air_tag) { |
| ... | @@ -11667,7 +11678,7 @@ fn analyzePtrArithmetic( | ... | @@ -11667,7 +11678,7 @@ fn analyzePtrArithmetic( |
| 11667 | } else break :rs ptr_src; | 11678 | } else break :rs ptr_src; |
| 11668 | }; | 11679 | }; |
| 11669 | | 11680 | |
| 11670 | try sema.requireRuntimeBlock(block, runtime_src); | 11681 | try sema.requireRuntimeBlock(block, op_src, runtime_src); |
| 11671 | return block.addInst(.{ | 11682 | return block.addInst(.{ |
| 11672 | .tag = air_tag, | 11683 | .tag = air_tag, |
| 11673 | .data = .{ .ty_pl = .{ | 11684 | .data = .{ .ty_pl = .{ |
| ... | @@ -11686,7 +11697,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In | ... | @@ -11686,7 +11697,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In |
| 11686 | | 11697 | |
| 11687 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 11698 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 11688 | const src = inst_data.src(); | 11699 | const src = inst_data.src(); |
| 11689 | const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node }; | 11700 | const ptr_src = src; // TODO better source location |
| 11690 | const ptr = try sema.resolveInst(inst_data.operand); | 11701 | const ptr = try sema.resolveInst(inst_data.operand); |
| 11691 | return sema.analyzeLoad(block, src, ptr, ptr_src); | 11702 | return sema.analyzeLoad(block, src, ptr, ptr_src); |
| 11692 | } | 11703 | } |
| ... | @@ -11734,7 +11745,7 @@ fn zirAsm( | ... | @@ -11734,7 +11745,7 @@ fn zirAsm( |
| 11734 | } | 11745 | } |
| 11735 | | 11746 | |
| 11736 | if (block.is_comptime) { | 11747 | if (block.is_comptime) { |
| 11737 | try sema.requireRuntimeBlock(block, src); | 11748 | try sema.requireRuntimeBlock(block, src, null); |
| 11738 | } | 11749 | } |
| 11739 | | 11750 | |
| 11740 | var extra_i = extra.end; | 11751 | var extra_i = extra.end; |
| ... | @@ -11896,10 +11907,10 @@ fn zirCmpEq( | ... | @@ -11896,10 +11907,10 @@ fn zirCmpEq( |
| 11896 | } | 11907 | } |
| 11897 | | 11908 | |
| 11898 | if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) { | 11909 | if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) { |
| 11899 | return sema.analyzeCmpUnionTag(block, lhs, lhs_src, rhs, rhs_src, op); | 11910 | return sema.analyzeCmpUnionTag(block, src, lhs, lhs_src, rhs, rhs_src, op); |
| 11900 | } | 11911 | } |
| 11901 | if (rhs_ty_tag == .Union and (lhs_ty_tag == .EnumLiteral or lhs_ty_tag == .Enum)) { | 11912 | if (rhs_ty_tag == .Union and (lhs_ty_tag == .EnumLiteral or lhs_ty_tag == .Enum)) { |
| 11902 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); | 11913 | return sema.analyzeCmpUnionTag(block, src, rhs, rhs_src, lhs, lhs_src, op); |
| 11903 | } | 11914 | } |
| 11904 | | 11915 | |
| 11905 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { | 11916 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { |
| ... | @@ -11926,7 +11937,7 @@ fn zirCmpEq( | ... | @@ -11926,7 +11937,7 @@ fn zirCmpEq( |
| 11926 | break :src lhs_src; | 11937 | break :src lhs_src; |
| 11927 | } | 11938 | } |
| 11928 | }; | 11939 | }; |
| 11929 | try sema.requireRuntimeBlock(block, runtime_src); | 11940 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 11930 | return block.addBinOp(air_tag, lhs, rhs); | 11941 | return block.addBinOp(air_tag, lhs, rhs); |
| 11931 | } | 11942 | } |
| 11932 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { | 11943 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { |
| ... | @@ -11944,6 +11955,7 @@ fn zirCmpEq( | ... | @@ -11944,6 +11955,7 @@ fn zirCmpEq( |
| 11944 | fn analyzeCmpUnionTag( | 11955 | fn analyzeCmpUnionTag( |
| 11945 | sema: *Sema, | 11956 | sema: *Sema, |
| 11946 | block: *Block, | 11957 | block: *Block, |
| | 11958 | src: LazySrcLoc, |
| 11947 | un: Air.Inst.Ref, | 11959 | un: Air.Inst.Ref, |
| 11948 | un_src: LazySrcLoc, | 11960 | un_src: LazySrcLoc, |
| 11949 | tag: Air.Inst.Ref, | 11961 | tag: Air.Inst.Ref, |
| ... | @@ -11965,7 +11977,7 @@ fn analyzeCmpUnionTag( | ... | @@ -11965,7 +11977,7 @@ fn analyzeCmpUnionTag( |
| 11965 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); | 11977 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); |
| 11966 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); | 11978 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); |
| 11967 | | 11979 | |
| 11968 | return sema.cmpSelf(block, coerced_union, coerced_tag, op, un_src, tag_src); | 11980 | return sema.cmpSelf(block, src, coerced_union, coerced_tag, op, un_src, tag_src); |
| 11969 | } | 11981 | } |
| 11970 | | 11982 | |
| 11971 | /// Only called for non-equality operators. See also `zirCmpEq`. | 11983 | /// Only called for non-equality operators. See also `zirCmpEq`. |
| ... | @@ -12021,7 +12033,7 @@ fn analyzeCmp( | ... | @@ -12021,7 +12033,7 @@ fn analyzeCmp( |
| 12021 | } | 12033 | } |
| 12022 | const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src); | 12034 | const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src); |
| 12023 | const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src); | 12035 | const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src); |
| 12024 | return sema.cmpSelf(block, casted_lhs, casted_rhs, op, lhs_src, rhs_src); | 12036 | return sema.cmpSelf(block, src, casted_lhs, casted_rhs, op, lhs_src, rhs_src); |
| 12025 | } | 12037 | } |
| 12026 | | 12038 | |
| 12027 | fn compareOperatorName(comp: std.math.CompareOperator) []const u8 { | 12039 | fn compareOperatorName(comp: std.math.CompareOperator) []const u8 { |
| ... | @@ -12038,6 +12050,7 @@ fn compareOperatorName(comp: std.math.CompareOperator) []const u8 { | ... | @@ -12038,6 +12050,7 @@ fn compareOperatorName(comp: std.math.CompareOperator) []const u8 { |
| 12038 | fn cmpSelf( | 12050 | fn cmpSelf( |
| 12039 | sema: *Sema, | 12051 | sema: *Sema, |
| 12040 | block: *Block, | 12052 | block: *Block, |
| | 12053 | src: LazySrcLoc, |
| 12041 | casted_lhs: Air.Inst.Ref, | 12054 | casted_lhs: Air.Inst.Ref, |
| 12042 | casted_rhs: Air.Inst.Ref, | 12055 | casted_rhs: Air.Inst.Ref, |
| 12043 | op: std.math.CompareOperator, | 12056 | op: std.math.CompareOperator, |
| ... | @@ -12065,7 +12078,7 @@ fn cmpSelf( | ... | @@ -12065,7 +12078,7 @@ fn cmpSelf( |
| 12065 | } else { | 12078 | } else { |
| 12066 | if (resolved_type.zigTypeTag() == .Bool) { | 12079 | if (resolved_type.zigTypeTag() == .Bool) { |
| 12067 | // We can lower bool eq/neq more efficiently. | 12080 | // We can lower bool eq/neq more efficiently. |
| 12068 | return sema.runtimeBoolCmp(block, op, casted_rhs, lhs_val.toBool(), rhs_src); | 12081 | return sema.runtimeBoolCmp(block, src, op, casted_rhs, lhs_val.toBool(), rhs_src); |
| 12069 | } | 12082 | } |
| 12070 | break :src rhs_src; | 12083 | break :src rhs_src; |
| 12071 | } | 12084 | } |
| ... | @@ -12075,13 +12088,13 @@ fn cmpSelf( | ... | @@ -12075,13 +12088,13 @@ fn cmpSelf( |
| 12075 | if (resolved_type.zigTypeTag() == .Bool) { | 12088 | if (resolved_type.zigTypeTag() == .Bool) { |
| 12076 | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { | 12089 | if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| { |
| 12077 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); | 12090 | if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool); |
| 12078 | return sema.runtimeBoolCmp(block, op, casted_lhs, rhs_val.toBool(), lhs_src); | 12091 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src); |
| 12079 | } | 12092 | } |
| 12080 | } | 12093 | } |
| 12081 | break :src lhs_src; | 12094 | break :src lhs_src; |
| 12082 | } | 12095 | } |
| 12083 | }; | 12096 | }; |
| 12084 | try sema.requireRuntimeBlock(block, runtime_src); | 12097 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 12085 | if (resolved_type.zigTypeTag() == .Vector) { | 12098 | if (resolved_type.zigTypeTag() == .Vector) { |
| 12086 | const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.@"bool"); | 12099 | const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.@"bool"); |
| 12087 | const result_ty_ref = try sema.addType(result_ty); | 12100 | const result_ty_ref = try sema.addType(result_ty); |
| ... | @@ -12098,13 +12111,14 @@ fn cmpSelf( | ... | @@ -12098,13 +12111,14 @@ fn cmpSelf( |
| 12098 | fn runtimeBoolCmp( | 12111 | fn runtimeBoolCmp( |
| 12099 | sema: *Sema, | 12112 | sema: *Sema, |
| 12100 | block: *Block, | 12113 | block: *Block, |
| | 12114 | src: LazySrcLoc, |
| 12101 | op: std.math.CompareOperator, | 12115 | op: std.math.CompareOperator, |
| 12102 | lhs: Air.Inst.Ref, | 12116 | lhs: Air.Inst.Ref, |
| 12103 | rhs: bool, | 12117 | rhs: bool, |
| 12104 | runtime_src: LazySrcLoc, | 12118 | runtime_src: LazySrcLoc, |
| 12105 | ) CompileError!Air.Inst.Ref { | 12119 | ) CompileError!Air.Inst.Ref { |
| 12106 | if ((op == .neq) == rhs) { | 12120 | if ((op == .neq) == rhs) { |
| 12107 | try sema.requireRuntimeBlock(block, runtime_src); | 12121 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 12108 | return block.addTyOp(.not, Type.bool, lhs); | 12122 | return block.addTyOp(.not, Type.bool, lhs); |
| 12109 | } else { | 12123 | } else { |
| 12110 | return lhs; | 12124 | return lhs; |
| ... | @@ -12226,7 +12240,7 @@ fn zirRetAddr( | ... | @@ -12226,7 +12240,7 @@ fn zirRetAddr( |
| 12226 | extended: Zir.Inst.Extended.InstData, | 12240 | extended: Zir.Inst.Extended.InstData, |
| 12227 | ) CompileError!Air.Inst.Ref { | 12241 | ) CompileError!Air.Inst.Ref { |
| 12228 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); | 12242 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); |
| 12229 | try sema.requireRuntimeBlock(block, src); | 12243 | try sema.requireRuntimeBlock(block, src, null); |
| 12230 | return try block.addNoOp(.ret_addr); | 12244 | return try block.addNoOp(.ret_addr); |
| 12231 | } | 12245 | } |
| 12232 | | 12246 | |
| ... | @@ -12236,7 +12250,7 @@ fn zirFrameAddress( | ... | @@ -12236,7 +12250,7 @@ fn zirFrameAddress( |
| 12236 | extended: Zir.Inst.Extended.InstData, | 12250 | extended: Zir.Inst.Extended.InstData, |
| 12237 | ) CompileError!Air.Inst.Ref { | 12251 | ) CompileError!Air.Inst.Ref { |
| 12238 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); | 12252 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); |
| 12239 | try sema.requireRuntimeBlock(block, src); | 12253 | try sema.requireRuntimeBlock(block, src, null); |
| 12240 | return try block.addNoOp(.frame_addr); | 12254 | return try block.addNoOp(.frame_addr); |
| 12241 | } | 12255 | } |
| 12242 | | 12256 | |
| ... | @@ -13305,7 +13319,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13305,7 +13319,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13305 | else | 13319 | else |
| 13306 | Air.Inst.Ref.bool_true; | 13320 | Air.Inst.Ref.bool_true; |
| 13307 | } | 13321 | } |
| 13308 | try sema.requireRuntimeBlock(block, src); | 13322 | try sema.requireRuntimeBlock(block, src, null); |
| 13309 | return block.addTyOp(.not, Type.bool, operand); | 13323 | return block.addTyOp(.not, Type.bool, operand); |
| 13310 | } | 13324 | } |
| 13311 | | 13325 | |
| ... | @@ -13690,7 +13704,7 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -13690,7 +13704,7 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 13690 | if (block.is_comptime or inst_data.force_comptime) { | 13704 | if (block.is_comptime or inst_data.force_comptime) { |
| 13691 | return sema.fail(block, src, "reached unreachable code", .{}); | 13705 | return sema.fail(block, src, "reached unreachable code", .{}); |
| 13692 | } | 13706 | } |
| 13693 | try sema.requireRuntimeBlock(block, src); | 13707 | try sema.requireFunctionBlock(block, src); |
| 13694 | // TODO Add compile error for @optimizeFor occurring too late in a scope. | 13708 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 13695 | try block.addUnreachable(src, true); | 13709 | try block.addUnreachable(src, true); |
| 13696 | return always_noreturn; | 13710 | return always_noreturn; |
| ... | @@ -13752,7 +13766,6 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir | ... | @@ -13752,7 +13766,6 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir |
| 13752 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); | 13766 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); |
| 13753 | return sema.analyzeRet(block, operand, src); | 13767 | return sema.analyzeRet(block, operand, src); |
| 13754 | } | 13768 | } |
| 13755 | try sema.requireRuntimeBlock(block, src); | | |
| 13756 | _ = try block.addUnOp(.ret_load, ret_ptr); | 13769 | _ = try block.addUnOp(.ret_load, ret_ptr); |
| 13757 | return always_noreturn; | 13770 | return always_noreturn; |
| 13758 | } | 13771 | } |
| ... | @@ -13874,14 +13887,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13874,14 +13887,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13874 | const sentinel = if (inst_data.flags.has_sentinel) blk: { | 13887 | const sentinel = if (inst_data.flags.has_sentinel) blk: { |
| 13875 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 13888 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13876 | extra_i += 1; | 13889 | extra_i += 1; |
| 13877 | break :blk (try sema.resolveInstConst(block, sentinel_src, ref)).val; | 13890 | break :blk (try sema.resolveInstConst(block, sentinel_src, ref, "pointer sentinel value must be comptime known")).val; |
| 13878 | } else null; | 13891 | } else null; |
| 13879 | | 13892 | |
| 13880 | const abi_align: u32 = if (inst_data.flags.has_align) blk: { | 13893 | const abi_align: u32 = if (inst_data.flags.has_align) blk: { |
| 13881 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 13894 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13882 | extra_i += 1; | 13895 | extra_i += 1; |
| 13883 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); | 13896 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); |
| 13884 | const val = try sema.resolveConstValue(block, align_src, coerced); | 13897 | const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime known"); |
| 13885 | // Check if this happens to be the lazy alignment of our element type, in | 13898 | // Check if this happens to be the lazy alignment of our element type, in |
| 13886 | // which case we can make this 0 without resolving it. | 13899 | // which case we can make this 0 without resolving it. |
| 13887 | if (val.castTag(.lazy_align)) |payload| { | 13900 | if (val.castTag(.lazy_align)) |payload| { |
| ... | @@ -13902,14 +13915,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13902,14 +13915,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13902 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { | 13915 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { |
| 13903 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 13916 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13904 | extra_i += 1; | 13917 | extra_i += 1; |
| 13905 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16); | 13918 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime known"); |
| 13906 | break :blk @intCast(u16, bit_offset); | 13919 | break :blk @intCast(u16, bit_offset); |
| 13907 | } else 0; | 13920 | } else 0; |
| 13908 | | 13921 | |
| 13909 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { | 13922 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 13910 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); | 13923 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13911 | extra_i += 1; | 13924 | extra_i += 1; |
| 13912 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16); | 13925 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime known"); |
| 13913 | break :blk @intCast(u16, host_size); | 13926 | break :blk @intCast(u16, host_size); |
| 13914 | } else 0; | 13927 | } else 0; |
| 13915 | | 13928 | |
| ... | @@ -14014,7 +14027,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -14014,7 +14027,7 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 14014 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 14027 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 14015 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; | 14028 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 14016 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); | 14029 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); |
| 14017 | const field_name = try sema.resolveConstString(block, field_src, extra.field_name); | 14030 | const field_name = try sema.resolveConstString(block, field_src, extra.field_name, "name of field being initialized must be comptime known"); |
| 14018 | const init = try sema.resolveInst(extra.init); | 14031 | const init = try sema.resolveInst(extra.init); |
| 14019 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); | 14032 | return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src); |
| 14020 | } | 14033 | } |
| ... | @@ -14041,7 +14054,7 @@ fn unionInit( | ... | @@ -14041,7 +14054,7 @@ fn unionInit( |
| 14041 | })); | 14054 | })); |
| 14042 | } | 14055 | } |
| 14043 | | 14056 | |
| 14044 | try sema.requireRuntimeBlock(block, init_src); | 14057 | try sema.requireRuntimeBlock(block, init_src, null); |
| 14045 | _ = union_ty_src; | 14058 | _ = union_ty_src; |
| 14046 | try sema.queueFullTypeResolution(union_ty); | 14059 | try sema.queueFullTypeResolution(union_ty); |
| 14047 | return block.addUnionInit(union_ty, field_index, init); | 14060 | return block.addUnionInit(union_ty, field_index, init); |
| ... | @@ -14146,7 +14159,7 @@ fn zirStructInit( | ... | @@ -14146,7 +14159,7 @@ fn zirStructInit( |
| 14146 | return alloc; | 14159 | return alloc; |
| 14147 | } | 14160 | } |
| 14148 | | 14161 | |
| 14149 | try sema.requireRuntimeBlock(block, src); | 14162 | try sema.requireRuntimeBlock(block, src, null); |
| 14150 | try sema.queueFullTypeResolution(resolved_ty); | 14163 | try sema.queueFullTypeResolution(resolved_ty); |
| 14151 | return block.addUnionInit(resolved_ty, field_index, init_inst); | 14164 | return block.addUnionInit(resolved_ty, field_index, init_inst); |
| 14152 | } else if (resolved_ty.isAnonStruct()) { | 14165 | } else if (resolved_ty.isAnonStruct()) { |
| ... | @@ -14251,7 +14264,7 @@ fn finishStructInit( | ... | @@ -14251,7 +14264,7 @@ fn finishStructInit( |
| 14251 | return alloc; | 14264 | return alloc; |
| 14252 | } | 14265 | } |
| 14253 | | 14266 | |
| 14254 | try sema.requireRuntimeBlock(block, dest_src); | 14267 | try sema.requireRuntimeBlock(block, dest_src, null); |
| 14255 | try sema.queueFullTypeResolution(struct_ty); | 14268 | try sema.queueFullTypeResolution(struct_ty); |
| 14256 | return block.addAggregateInit(struct_ty, field_inits); | 14269 | return block.addAggregateInit(struct_ty, field_inits); |
| 14257 | } | 14270 | } |
| ... | @@ -14301,7 +14314,7 @@ fn zirStructInitAnon( | ... | @@ -14301,7 +14314,7 @@ fn zirStructInitAnon( |
| 14301 | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); | 14314 | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); |
| 14302 | }; | 14315 | }; |
| 14303 | | 14316 | |
| 14304 | try sema.requireRuntimeBlock(block, runtime_src); | 14317 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 14305 | | 14318 | |
| 14306 | if (is_ref) { | 14319 | if (is_ref) { |
| 14307 | const target = sema.mod.getTarget(); | 14320 | const target = sema.mod.getTarget(); |
| ... | @@ -14393,7 +14406,7 @@ fn zirArrayInit( | ... | @@ -14393,7 +14406,7 @@ fn zirArrayInit( |
| 14393 | return sema.addConstantMaybeRef(block, src, array_ty, array_val, is_ref); | 14406 | return sema.addConstantMaybeRef(block, src, array_ty, array_val, is_ref); |
| 14394 | }; | 14407 | }; |
| 14395 | | 14408 | |
| 14396 | try sema.requireRuntimeBlock(block, runtime_src); | 14409 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 14397 | try sema.queueFullTypeResolution(array_ty); | 14410 | try sema.queueFullTypeResolution(array_ty); |
| 14398 | | 14411 | |
| 14399 | if (is_ref) { | 14412 | if (is_ref) { |
| ... | @@ -14479,7 +14492,7 @@ fn zirArrayInitAnon( | ... | @@ -14479,7 +14492,7 @@ fn zirArrayInitAnon( |
| 14479 | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); | 14492 | return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref); |
| 14480 | }; | 14493 | }; |
| 14481 | | 14494 | |
| 14482 | try sema.requireRuntimeBlock(block, runtime_src); | 14495 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 14483 | | 14496 | |
| 14484 | if (is_ref) { | 14497 | if (is_ref) { |
| 14485 | const target = sema.mod.getTarget(); | 14498 | const target = sema.mod.getTarget(); |
| ... | @@ -14538,7 +14551,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -14538,7 +14551,7 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 14538 | const ty_src = inst_data.src(); | 14551 | const ty_src = inst_data.src(); |
| 14539 | const field_src = inst_data.src(); | 14552 | const field_src = inst_data.src(); |
| 14540 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 14553 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 14541 | const field_name = try sema.resolveConstString(block, field_src, extra.field_name); | 14554 | const field_name = try sema.resolveConstString(block, field_src, extra.field_name, "field name must be comptime known"); |
| 14542 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); | 14555 | return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src); |
| 14543 | } | 14556 | } |
| 14544 | | 14557 | |
| ... | @@ -14728,7 +14741,7 @@ fn zirUnaryMath( | ... | @@ -14728,7 +14741,7 @@ fn zirUnaryMath( |
| 14728 | ); | 14741 | ); |
| 14729 | } | 14742 | } |
| 14730 | | 14743 | |
| 14731 | try sema.requireRuntimeBlock(block, operand_src); | 14744 | try sema.requireRuntimeBlock(block, operand_src, null); |
| 14732 | return block.addUnOp(air_tag, operand); | 14745 | return block.addUnOp(air_tag, operand); |
| 14733 | }, | 14746 | }, |
| 14734 | .ComptimeFloat, .Float => { | 14747 | .ComptimeFloat, .Float => { |
| ... | @@ -14739,7 +14752,7 @@ fn zirUnaryMath( | ... | @@ -14739,7 +14752,7 @@ fn zirUnaryMath( |
| 14739 | return sema.addConstant(operand_ty, result_val); | 14752 | return sema.addConstant(operand_ty, result_val); |
| 14740 | } | 14753 | } |
| 14741 | | 14754 | |
| 14742 | try sema.requireRuntimeBlock(block, operand_src); | 14755 | try sema.requireRuntimeBlock(block, operand_src, null); |
| 14743 | return block.addUnOp(air_tag, operand); | 14756 | return block.addUnOp(air_tag, operand); |
| 14744 | }, | 14757 | }, |
| 14745 | else => unreachable, | 14758 | else => unreachable, |
| ... | @@ -14757,7 +14770,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -14757,7 +14770,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 14757 | try sema.resolveTypeLayout(block, operand_src, operand_ty); | 14770 | try sema.resolveTypeLayout(block, operand_src, operand_ty); |
| 14758 | const enum_ty = switch (operand_ty.zigTypeTag()) { | 14771 | const enum_ty = switch (operand_ty.zigTypeTag()) { |
| 14759 | .EnumLiteral => { | 14772 | .EnumLiteral => { |
| 14760 | const val = try sema.resolveConstValue(block, operand_src, operand); | 14773 | const val = try sema.resolveConstValue(block, .unneeded, operand, undefined); |
| 14761 | const bytes = val.castTag(.enum_literal).?.data; | 14774 | const bytes = val.castTag(.enum_literal).?.data; |
| 14762 | return sema.addStrLit(block, bytes); | 14775 | return sema.addStrLit(block, bytes); |
| 14763 | }, | 14776 | }, |
| ... | @@ -14809,7 +14822,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -14809,7 +14822,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 14809 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 14822 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 14810 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 14823 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 14811 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 14824 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 14812 | const val = try sema.resolveConstValue(block, operand_src, type_info); | 14825 | const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime known"); |
| 14813 | const union_val = val.cast(Value.Payload.Union).?.data; | 14826 | const union_val = val.cast(Value.Payload.Union).?.data; |
| 14814 | const tag_ty = type_info_ty.unionTagType().?; | 14827 | const tag_ty = type_info_ty.unionTagType().?; |
| 14815 | const target = mod.getTarget(); | 14828 | const target = mod.getTarget(); |
| ... | @@ -15493,10 +15506,10 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -15493,10 +15506,10 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15493 | const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty); | 15506 | const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty); |
| 15494 | return sema.addConstant(dest_ty, result_val); | 15507 | return sema.addConstant(dest_ty, result_val); |
| 15495 | } else if (dest_ty.zigTypeTag() == .ComptimeInt) { | 15508 | } else if (dest_ty.zigTypeTag() == .ComptimeInt) { |
| 15496 | return sema.failWithNeededComptime(block, operand_src); | 15509 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime known"); |
| 15497 | } | 15510 | } |
| 15498 | | 15511 | |
| 15499 | try sema.requireRuntimeBlock(block, operand_src); | 15512 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| 15500 | return block.addTyOp(.float_to_int, dest_ty, operand); | 15513 | return block.addTyOp(.float_to_int, dest_ty, operand); |
| 15501 | } | 15514 | } |
| 15502 | | 15515 | |
| ... | @@ -15517,10 +15530,10 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -15517,10 +15530,10 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15517 | const result_val = try val.intToFloat(sema.arena, operand_ty, dest_ty, target); | 15530 | const result_val = try val.intToFloat(sema.arena, operand_ty, dest_ty, target); |
| 15518 | return sema.addConstant(dest_ty, result_val); | 15531 | return sema.addConstant(dest_ty, result_val); |
| 15519 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { | 15532 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| 15520 | return sema.failWithNeededComptime(block, operand_src); | 15533 | return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime known"); |
| 15521 | } | 15534 | } |
| 15522 | | 15535 | |
| 15523 | try sema.requireRuntimeBlock(block, operand_src); | 15536 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| 15524 | return block.addTyOp(.int_to_float, dest_ty, operand); | 15537 | return block.addTyOp(.int_to_float, dest_ty, operand); |
| 15525 | } | 15538 | } |
| 15526 | | 15539 | |
| ... | @@ -15556,7 +15569,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15556,7 +15569,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15556 | return sema.addConstant(type_res, Value.initPayload(&val_payload.base)); | 15569 | return sema.addConstant(type_res, Value.initPayload(&val_payload.base)); |
| 15557 | } | 15570 | } |
| 15558 | | 15571 | |
| 15559 | try sema.requireRuntimeBlock(block, src); | 15572 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 15560 | if (block.wantSafety()) { | 15573 | if (block.wantSafety()) { |
| 15561 | if (!type_res.isAllowzeroPtr()) { | 15574 | if (!type_res.isAllowzeroPtr()) { |
| 15562 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); | 15575 | const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); |
| ... | @@ -15653,7 +15666,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -15653,7 +15666,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 15653 | return sema.addConstant(dest_ty, val); | 15666 | return sema.addConstant(dest_ty, val); |
| 15654 | } | 15667 | } |
| 15655 | | 15668 | |
| 15656 | try sema.requireRuntimeBlock(block, src); | 15669 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 15657 | if (block.wantSafety() and !dest_ty.isAnyError()) { | 15670 | if (block.wantSafety() and !dest_ty.isAnyError()) { |
| 15658 | const err_int_inst = try block.addBitCast(Type.u16, operand); | 15671 | const err_int_inst = try block.addBitCast(Type.u16, operand); |
| 15659 | // TODO: Output a switch instead of chained OR's. | 15672 | // TODO: Output a switch instead of chained OR's. |
| ... | @@ -15808,7 +15821,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15808,7 +15821,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15808 | ); | 15821 | ); |
| 15809 | } | 15822 | } |
| 15810 | | 15823 | |
| 15811 | try sema.requireRuntimeBlock(block, src); | 15824 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 15812 | return block.addTyOp(.trunc, dest_ty, operand); | 15825 | return block.addTyOp(.trunc, dest_ty, operand); |
| 15813 | } | 15826 | } |
| 15814 | | 15827 | |
| ... | @@ -15851,6 +15864,7 @@ fn zirBitCount( | ... | @@ -15851,6 +15864,7 @@ fn zirBitCount( |
| 15851 | comptimeOp: fn (val: Value, ty: Type, target: std.Target) u64, | 15864 | comptimeOp: fn (val: Value, ty: Type, target: std.Target) u64, |
| 15852 | ) CompileError!Air.Inst.Ref { | 15865 | ) CompileError!Air.Inst.Ref { |
| 15853 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 15866 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 15867 | const src = inst_data.src(); |
| 15854 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 15868 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 15855 | const operand = try sema.resolveInst(inst_data.operand); | 15869 | const operand = try sema.resolveInst(inst_data.operand); |
| 15856 | const operand_ty = sema.typeOf(operand); | 15870 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -15883,7 +15897,7 @@ fn zirBitCount( | ... | @@ -15883,7 +15897,7 @@ fn zirBitCount( |
| 15883 | try Value.Tag.aggregate.create(sema.arena, elems), | 15897 | try Value.Tag.aggregate.create(sema.arena, elems), |
| 15884 | ); | 15898 | ); |
| 15885 | } else { | 15899 | } else { |
| 15886 | try sema.requireRuntimeBlock(block, operand_src); | 15900 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 15887 | return block.addTyOp(air_tag, result_ty, operand); | 15901 | return block.addTyOp(air_tag, result_ty, operand); |
| 15888 | } | 15902 | } |
| 15889 | }, | 15903 | }, |
| ... | @@ -15892,7 +15906,7 @@ fn zirBitCount( | ... | @@ -15892,7 +15906,7 @@ fn zirBitCount( |
| 15892 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); | 15906 | if (val.isUndef()) return sema.addConstUndef(result_scalar_ty); |
| 15893 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target)); | 15907 | return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target)); |
| 15894 | } else { | 15908 | } else { |
| 15895 | try sema.requireRuntimeBlock(block, operand_src); | 15909 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 15896 | return block.addTyOp(air_tag, result_scalar_ty, operand); | 15910 | return block.addTyOp(air_tag, result_scalar_ty, operand); |
| 15897 | } | 15911 | } |
| 15898 | }, | 15912 | }, |
| ... | @@ -15902,6 +15916,7 @@ fn zirBitCount( | ... | @@ -15902,6 +15916,7 @@ fn zirBitCount( |
| 15902 | | 15916 | |
| 15903 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15917 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15904 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 15918 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 15919 | const src = inst_data.src(); |
| 15905 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 15920 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 15906 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 15921 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 15907 | const operand = try sema.resolveInst(inst_data.operand); | 15922 | const operand = try sema.resolveInst(inst_data.operand); |
| ... | @@ -15930,7 +15945,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15930,7 +15945,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15930 | return sema.addConstant(operand_ty, result_val); | 15945 | return sema.addConstant(operand_ty, result_val); |
| 15931 | } else operand_src; | 15946 | } else operand_src; |
| 15932 | | 15947 | |
| 15933 | try sema.requireRuntimeBlock(block, runtime_src); | 15948 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 15934 | return block.addTyOp(.byte_swap, operand_ty, operand); | 15949 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| 15935 | }, | 15950 | }, |
| 15936 | .Vector => { | 15951 | .Vector => { |
| ... | @@ -15951,7 +15966,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15951,7 +15966,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15951 | ); | 15966 | ); |
| 15952 | } else operand_src; | 15967 | } else operand_src; |
| 15953 | | 15968 | |
| 15954 | try sema.requireRuntimeBlock(block, runtime_src); | 15969 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 15955 | return block.addTyOp(.byte_swap, operand_ty, operand); | 15970 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| 15956 | }, | 15971 | }, |
| 15957 | else => unreachable, | 15972 | else => unreachable, |
| ... | @@ -15960,6 +15975,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15960,6 +15975,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15960 | | 15975 | |
| 15961 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15976 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15962 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 15977 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| | 15978 | const src = inst_data.src(); |
| 15963 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 15979 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 15964 | const operand = try sema.resolveInst(inst_data.operand); | 15980 | const operand = try sema.resolveInst(inst_data.operand); |
| 15965 | const operand_ty = sema.typeOf(operand); | 15981 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -15978,7 +15994,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -15978,7 +15994,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15978 | return sema.addConstant(operand_ty, result_val); | 15994 | return sema.addConstant(operand_ty, result_val); |
| 15979 | } else operand_src; | 15995 | } else operand_src; |
| 15980 | | 15996 | |
| 15981 | try sema.requireRuntimeBlock(block, runtime_src); | 15997 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 15982 | return block.addTyOp(.bit_reverse, operand_ty, operand); | 15998 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| 15983 | }, | 15999 | }, |
| 15984 | .Vector => { | 16000 | .Vector => { |
| ... | @@ -15999,7 +16015,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -15999,7 +16015,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15999 | ); | 16015 | ); |
| 16000 | } else operand_src; | 16016 | } else operand_src; |
| 16001 | | 16017 | |
| 16002 | try sema.requireRuntimeBlock(block, runtime_src); | 16018 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 16003 | return block.addTyOp(.bit_reverse, operand_ty, operand); | 16019 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| 16004 | }, | 16020 | }, |
| 16005 | else => unreachable, | 16021 | else => unreachable, |
| ... | @@ -16026,7 +16042,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 | ... | @@ -16026,7 +16042,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 |
| 16026 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16042 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16027 | | 16043 | |
| 16028 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 16044 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| 16029 | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs); | 16045 | const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime known"); |
| 16030 | const target = sema.mod.getTarget(); | 16046 | const target = sema.mod.getTarget(); |
| 16031 | | 16047 | |
| 16032 | try sema.resolveTypeLayout(block, lhs_src, ty); | 16048 | try sema.resolveTypeLayout(block, lhs_src, ty); |
| ... | @@ -16447,19 +16463,19 @@ fn resolveExportOptions( | ... | @@ -16447,19 +16463,19 @@ fn resolveExportOptions( |
| 16447 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 16463 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 16448 | | 16464 | |
| 16449 | const name_operand = try sema.fieldVal(block, src, options, "name", src); | 16465 | const name_operand = try sema.fieldVal(block, src, options, "name", src); |
| 16450 | const name_val = try sema.resolveConstValue(block, src, name_operand); | 16466 | const name_val = try sema.resolveConstValue(block, src, name_operand, "name of exported value must be comptime known"); |
| 16451 | const name_ty = Type.initTag(.const_slice_u8); | 16467 | const name_ty = Type.initTag(.const_slice_u8); |
| 16452 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, sema.mod); | 16468 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, sema.mod); |
| 16453 | | 16469 | |
| 16454 | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", src); | 16470 | const linkage_operand = try sema.fieldVal(block, src, options, "linkage", src); |
| 16455 | const linkage_val = try sema.resolveConstValue(block, src, linkage_operand); | 16471 | const linkage_val = try sema.resolveConstValue(block, src, linkage_operand, "linkage of exported value must be comptime known"); |
| 16456 | const linkage = linkage_val.toEnum(std.builtin.GlobalLinkage); | 16472 | const linkage = linkage_val.toEnum(std.builtin.GlobalLinkage); |
| 16457 | | 16473 | |
| 16458 | const section = try sema.fieldVal(block, src, options, "section", src); | 16474 | const section = try sema.fieldVal(block, src, options, "section", src); |
| 16459 | const section_val = try sema.resolveConstValue(block, src, section); | 16475 | const section_val = try sema.resolveConstValue(block, src, section, "linksection of exported value must be comptime known"); |
| 16460 | | 16476 | |
| 16461 | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", src); | 16477 | const visibility_operand = try sema.fieldVal(block, src, options, "visibility", src); |
| 16462 | const visibility_val = try sema.resolveConstValue(block, src, visibility_operand); | 16478 | const visibility_val = try sema.resolveConstValue(block, src, visibility_operand, "visibility of exported value must be comptime known"); |
| 16463 | const visibility = visibility_val.toEnum(std.builtin.SymbolVisibility); | 16479 | const visibility = visibility_val.toEnum(std.builtin.SymbolVisibility); |
| 16464 | | 16480 | |
| 16465 | if (name.len < 1) { | 16481 | if (name.len < 1) { |
| ... | @@ -16490,11 +16506,12 @@ fn resolveBuiltinEnum( | ... | @@ -16490,11 +16506,12 @@ fn resolveBuiltinEnum( |
| 16490 | src: LazySrcLoc, | 16506 | src: LazySrcLoc, |
| 16491 | zir_ref: Zir.Inst.Ref, | 16507 | zir_ref: Zir.Inst.Ref, |
| 16492 | comptime name: []const u8, | 16508 | comptime name: []const u8, |
| | 16509 | reason: []const u8, |
| 16493 | ) CompileError!@field(std.builtin, name) { | 16510 | ) CompileError!@field(std.builtin, name) { |
| 16494 | const ty = try sema.getBuiltinType(block, src, name); | 16511 | const ty = try sema.getBuiltinType(block, src, name); |
| 16495 | const air_ref = try sema.resolveInst(zir_ref); | 16512 | const air_ref = try sema.resolveInst(zir_ref); |
| 16496 | const coerced = try sema.coerce(block, ty, air_ref, src); | 16513 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 16497 | const val = try sema.resolveConstValue(block, src, coerced); | 16514 | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 16498 | return val.toEnum(@field(std.builtin, name)); | 16515 | return val.toEnum(@field(std.builtin, name)); |
| 16499 | } | 16516 | } |
| 16500 | | 16517 | |
| ... | @@ -16503,8 +16520,9 @@ fn resolveAtomicOrder( | ... | @@ -16503,8 +16520,9 @@ fn resolveAtomicOrder( |
| 16503 | block: *Block, | 16520 | block: *Block, |
| 16504 | src: LazySrcLoc, | 16521 | src: LazySrcLoc, |
| 16505 | zir_ref: Zir.Inst.Ref, | 16522 | zir_ref: Zir.Inst.Ref, |
| | 16523 | reason: []const u8, |
| 16506 | ) CompileError!std.builtin.AtomicOrder { | 16524 | ) CompileError!std.builtin.AtomicOrder { |
| 16507 | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicOrder"); | 16525 | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicOrder", reason); |
| 16508 | } | 16526 | } |
| 16509 | | 16527 | |
| 16510 | fn resolveAtomicRmwOp( | 16528 | fn resolveAtomicRmwOp( |
| ... | @@ -16513,7 +16531,7 @@ fn resolveAtomicRmwOp( | ... | @@ -16513,7 +16531,7 @@ fn resolveAtomicRmwOp( |
| 16513 | src: LazySrcLoc, | 16531 | src: LazySrcLoc, |
| 16514 | zir_ref: Zir.Inst.Ref, | 16532 | zir_ref: Zir.Inst.Ref, |
| 16515 | ) CompileError!std.builtin.AtomicRmwOp { | 16533 | ) CompileError!std.builtin.AtomicRmwOp { |
| 16516 | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicRmwOp"); | 16534 | return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime known"); |
| 16517 | } | 16535 | } |
| 16518 | | 16536 | |
| 16519 | fn zirCmpxchg( | 16537 | fn zirCmpxchg( |
| ... | @@ -16546,8 +16564,8 @@ fn zirCmpxchg( | ... | @@ -16546,8 +16564,8 @@ fn zirCmpxchg( |
| 16546 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 16564 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 16547 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 16565 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 16548 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); | 16566 | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); |
| 16549 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order); | 16567 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, "atomic order of cmpxchg success must be comptime known"); |
| 16550 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); | 16568 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, "atomic order of cmpxchg failure must be comptime known"); |
| 16551 | | 16569 | |
| 16552 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { | 16570 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { |
| 16553 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); | 16571 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| ... | @@ -16592,7 +16610,7 @@ fn zirCmpxchg( | ... | @@ -16592,7 +16610,7 @@ fn zirCmpxchg( |
| 16592 | const flags: u32 = @as(u32, @enumToInt(success_order)) | | 16610 | const flags: u32 = @as(u32, @enumToInt(success_order)) | |
| 16593 | (@as(u32, @enumToInt(failure_order)) << 3); | 16611 | (@as(u32, @enumToInt(failure_order)) << 3); |
| 16594 | | 16612 | |
| 16595 | try sema.requireRuntimeBlock(block, runtime_src); | 16613 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 16596 | return block.addInst(.{ | 16614 | return block.addInst(.{ |
| 16597 | .tag = air_tag, | 16615 | .tag = air_tag, |
| 16598 | .data = .{ .ty_pl = .{ | 16616 | .data = .{ .ty_pl = .{ |
| ... | @@ -16612,7 +16630,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -16612,7 +16630,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 16612 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16630 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16613 | const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 16631 | const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 16614 | const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 16632 | const scalar_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 16615 | const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32)); | 16633 | const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector splat destination length must be comptime known")); |
| 16616 | const scalar = try sema.resolveInst(extra.rhs); | 16634 | const scalar = try sema.resolveInst(extra.rhs); |
| 16617 | const scalar_ty = sema.typeOf(scalar); | 16635 | const scalar_ty = sema.typeOf(scalar); |
| 16618 | try sema.checkVectorElemType(block, scalar_src, scalar_ty); | 16636 | try sema.checkVectorElemType(block, scalar_src, scalar_ty); |
| ... | @@ -16629,7 +16647,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -16629,7 +16647,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 16629 | ); | 16647 | ); |
| 16630 | } | 16648 | } |
| 16631 | | 16649 | |
| 16632 | try sema.requireRuntimeBlock(block, scalar_src); | 16650 | try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src); |
| 16633 | return block.addTyOp(.splat, vector_ty, scalar); | 16651 | return block.addTyOp(.splat, vector_ty, scalar); |
| 16634 | } | 16652 | } |
| 16635 | | 16653 | |
| ... | @@ -16638,7 +16656,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -16638,7 +16656,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16638 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16656 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16639 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 16657 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 16640 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 16658 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 16641 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp"); | 16659 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", "@reduce operation must be comptime known"); |
| 16642 | const operand = try sema.resolveInst(extra.rhs); | 16660 | const operand = try sema.resolveInst(extra.rhs); |
| 16643 | const operand_ty = sema.typeOf(operand); | 16661 | const operand_ty = sema.typeOf(operand); |
| 16644 | const target = sema.mod.getTarget(); | 16662 | const target = sema.mod.getTarget(); |
| ... | @@ -16693,7 +16711,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -16693,7 +16711,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 16693 | return sema.addConstant(scalar_ty, accum); | 16711 | return sema.addConstant(scalar_ty, accum); |
| 16694 | } | 16712 | } |
| 16695 | | 16713 | |
| 16696 | try sema.requireRuntimeBlock(block, operand_src); | 16714 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); |
| 16697 | return block.addInst(.{ | 16715 | return block.addInst(.{ |
| 16698 | .tag = .reduce, | 16716 | .tag = .reduce, |
| 16699 | .data = .{ .reduce = .{ | 16717 | .data = .{ .reduce = .{ |
| ... | @@ -16725,7 +16743,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -16725,7 +16743,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 16725 | .elem_type = Type.@"i32", | 16743 | .elem_type = Type.@"i32", |
| 16726 | }); | 16744 | }); |
| 16727 | mask = try sema.coerce(block, mask_ty, mask, mask_src); | 16745 | mask = try sema.coerce(block, mask_ty, mask, mask_src); |
| 16728 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask); | 16746 | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime known"); |
| 16729 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(u32, mask_len)); | 16747 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(u32, mask_len)); |
| 16730 | } | 16748 | } |
| 16731 | | 16749 | |
| ... | @@ -16897,6 +16915,7 @@ fn analyzeShuffle( | ... | @@ -16897,6 +16915,7 @@ fn analyzeShuffle( |
| 16897 | fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 16915 | fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 16898 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; | 16916 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; |
| 16899 | | 16917 | |
| | 16918 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 16900 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 16919 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 16901 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 16920 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 16902 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | 16921 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; |
| ... | @@ -16968,7 +16987,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -16968,7 +16987,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 16968 | break :rs pred_src; | 16987 | break :rs pred_src; |
| 16969 | }; | 16988 | }; |
| 16970 | | 16989 | |
| 16971 | try sema.requireRuntimeBlock(block, runtime_src); | 16990 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 16972 | return block.addInst(.{ | 16991 | return block.addInst(.{ |
| 16973 | .tag = .select, | 16992 | .tag = .select, |
| 16974 | .data = .{ .pl_op = .{ | 16993 | .data = .{ .pl_op = .{ |
| ... | @@ -16992,7 +17011,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -16992,7 +17011,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 16992 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 17011 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 16993 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 17012 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 16994 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); | 17013 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); |
| 16995 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); | 17014 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicLoad must be comptime known"); |
| 16996 | | 17015 | |
| 16997 | switch (order) { | 17016 | switch (order) { |
| 16998 | .Release, .AcqRel => { | 17017 | .Release, .AcqRel => { |
| ... | @@ -17016,7 +17035,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -17016,7 +17035,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 17016 | } | 17035 | } |
| 17017 | } | 17036 | } |
| 17018 | | 17037 | |
| 17019 | try sema.requireRuntimeBlock(block, ptr_src); | 17038 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); |
| 17020 | return block.addInst(.{ | 17039 | return block.addInst(.{ |
| 17021 | .tag = .atomic_load, | 17040 | .tag = .atomic_load, |
| 17022 | .data = .{ .atomic_load = .{ | 17041 | .data = .{ .atomic_load = .{ |
| ... | @@ -17056,7 +17075,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17056,7 +17075,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17056 | }, | 17075 | }, |
| 17057 | else => {}, | 17076 | else => {}, |
| 17058 | } | 17077 | } |
| 17059 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); | 17078 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicRmW must be comptime known"); |
| 17060 | | 17079 | |
| 17061 | if (order == .Unordered) { | 17080 | if (order == .Unordered) { |
| 17062 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); | 17081 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| ... | @@ -17097,7 +17116,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17097,7 +17116,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17097 | | 17116 | |
| 17098 | const flags: u32 = @as(u32, @enumToInt(order)) | (@as(u32, @enumToInt(op)) << 3); | 17117 | const flags: u32 = @as(u32, @enumToInt(order)) | (@as(u32, @enumToInt(op)) << 3); |
| 17099 | | 17118 | |
| 17100 | try sema.requireRuntimeBlock(block, runtime_src); | 17119 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 17101 | return block.addInst(.{ | 17120 | return block.addInst(.{ |
| 17102 | .tag = .atomic_rmw, | 17121 | .tag = .atomic_rmw, |
| 17103 | .data = .{ .pl_op = .{ | 17122 | .data = .{ .pl_op = .{ |
| ... | @@ -17124,7 +17143,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -17124,7 +17143,7 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17124 | const elem_ty = sema.typeOf(operand); | 17143 | const elem_ty = sema.typeOf(operand); |
| 17125 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 17144 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 17126 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); | 17145 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 17127 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); | 17146 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicStore must be comptime known"); |
| 17128 | | 17147 | |
| 17129 | const air_tag: Air.Inst.Tag = switch (order) { | 17148 | const air_tag: Air.Inst.Tag = switch (order) { |
| 17130 | .Acquire, .AcqRel => { | 17149 | .Acquire, .AcqRel => { |
| ... | @@ -17196,7 +17215,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -17196,7 +17215,7 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 17196 | break :rs mulend1_src; | 17215 | break :rs mulend1_src; |
| 17197 | }; | 17216 | }; |
| 17198 | | 17217 | |
| 17199 | try sema.requireRuntimeBlock(block, runtime_src); | 17218 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 17200 | return block.addInst(.{ | 17219 | return block.addInst(.{ |
| 17201 | .tag = .mul_add, | 17220 | .tag = .mul_add, |
| 17202 | .data = .{ .pl_op = .{ | 17221 | .data = .{ .pl_op = .{ |
| ... | @@ -17229,10 +17248,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -17229,10 +17248,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17229 | const coerced_options = try sema.coerce(block, call_options_ty, options, options_src); | 17248 | const coerced_options = try sema.coerce(block, call_options_ty, options, options_src); |
| 17230 | | 17249 | |
| 17231 | const modifier = try sema.fieldVal(block, options_src, coerced_options, "modifier", options_src); | 17250 | const modifier = try sema.fieldVal(block, options_src, coerced_options, "modifier", options_src); |
| 17232 | const modifier_val = try sema.resolveConstValue(block, options_src, modifier); | 17251 | const modifier_val = try sema.resolveConstValue(block, options_src, modifier, "call modifier must be comptime known"); |
| 17233 | | 17252 | |
| 17234 | const stack = try sema.fieldVal(block, options_src, coerced_options, "stack", options_src); | 17253 | const stack = try sema.fieldVal(block, options_src, coerced_options, "stack", options_src); |
| 17235 | const stack_val = try sema.resolveConstValue(block, options_src, stack); | 17254 | const stack_val = try sema.resolveConstValue(block, options_src, stack, "call stack value must be comptime known"); |
| 17236 | | 17255 | |
| 17237 | if (!stack_val.isNull()) { | 17256 | if (!stack_val.isNull()) { |
| 17238 | return sema.fail(block, options_src, "TODO: implement @call with stack", .{}); | 17257 | return sema.fail(block, options_src, "TODO: implement @call with stack", .{}); |
| ... | @@ -17293,7 +17312,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -17293,7 +17312,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17293 | | 17312 | |
| 17294 | // Desugar bound functions here | 17313 | // Desugar bound functions here |
| 17295 | if (sema.typeOf(func).tag() == .bound_fn) { | 17314 | if (sema.typeOf(func).tag() == .bound_fn) { |
| 17296 | const bound_func = try sema.resolveValue(block, func_src, func); | 17315 | const bound_func = try sema.resolveValue(block, .unneeded, func, undefined); |
| 17297 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; | 17316 | const bound_data = &bound_func.cast(Value.Payload.BoundFn).?.data; |
| 17298 | func = bound_data.func_inst; | 17317 | func = bound_data.func_inst; |
| 17299 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount() + 1); | 17318 | resolved_args = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount() + 1); |
| ... | @@ -17320,7 +17339,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -17320,7 +17339,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 17320 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 17339 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 17321 | | 17340 | |
| 17322 | const struct_ty = try sema.resolveType(block, ty_src, extra.parent_type); | 17341 | const struct_ty = try sema.resolveType(block, ty_src, extra.parent_type); |
| 17323 | const field_name = try sema.resolveConstString(block, name_src, extra.field_name); | 17342 | const field_name = try sema.resolveConstString(block, name_src, extra.field_name, "field name must be comptime known"); |
| 17324 | const field_ptr = try sema.resolveInst(extra.field_ptr); | 17343 | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 17325 | const field_ptr_ty = sema.typeOf(field_ptr); | 17344 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 17326 | | 17345 | |
| ... | @@ -17385,7 +17404,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -17385,7 +17404,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 17385 | return sema.addConstant(result_ptr, payload.data.container_ptr); | 17404 | return sema.addConstant(result_ptr, payload.data.container_ptr); |
| 17386 | } | 17405 | } |
| 17387 | | 17406 | |
| 17388 | try sema.requireRuntimeBlock(block, src); | 17407 | try sema.requireRuntimeBlock(block, src, ptr_src); |
| 17389 | return block.addInst(.{ | 17408 | return block.addInst(.{ |
| 17390 | .tag = .field_parent_ptr, | 17409 | .tag = .field_parent_ptr, |
| 17391 | .data = .{ .ty_pl = .{ | 17410 | .data = .{ .ty_pl = .{ |
| ... | @@ -17466,7 +17485,7 @@ fn analyzeMinMax( | ... | @@ -17466,7 +17485,7 @@ fn analyzeMinMax( |
| 17466 | break :rs lhs_src; | 17485 | break :rs lhs_src; |
| 17467 | }; | 17486 | }; |
| 17468 | | 17487 | |
| 17469 | try sema.requireRuntimeBlock(block, runtime_src); | 17488 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 17470 | return block.addBinOp(air_tag, simd_op.lhs, simd_op.rhs); | 17489 | return block.addBinOp(air_tag, simd_op.lhs, simd_op.rhs); |
| 17471 | } | 17490 | } |
| 17472 | | 17491 | |
| ... | @@ -17514,7 +17533,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -17514,7 +17533,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 17514 | } else break :rs src_src; | 17533 | } else break :rs src_src; |
| 17515 | } else dest_src; | 17534 | } else dest_src; |
| 17516 | | 17535 | |
| 17517 | try sema.requireRuntimeBlock(block, runtime_src); | 17536 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 17518 | _ = try block.addInst(.{ | 17537 | _ = try block.addInst(.{ |
| 17519 | .tag = .memcpy, | 17538 | .tag = .memcpy, |
| 17520 | .data = .{ .pl_op = .{ | 17539 | .data = .{ .pl_op = .{ |
| ... | @@ -17556,7 +17575,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -17556,7 +17575,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 17556 | } else break :rs len_src; | 17575 | } else break :rs len_src; |
| 17557 | } else dest_src; | 17576 | } else dest_src; |
| 17558 | | 17577 | |
| 17559 | try sema.requireRuntimeBlock(block, runtime_src); | 17578 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 17560 | _ = try block.addInst(.{ | 17579 | _ = try block.addInst(.{ |
| 17561 | .tag = .memset, | 17580 | .tag = .memset, |
| 17562 | .data = .{ .pl_op = .{ | 17581 | .data = .{ .pl_op = .{ |
| ... | @@ -17652,7 +17671,7 @@ fn zirVarExtended( | ... | @@ -17652,7 +17671,7 @@ fn zirVarExtended( |
| 17652 | uncasted_init; | 17671 | uncasted_init; |
| 17653 | | 17672 | |
| 17654 | break :blk (try sema.resolveMaybeUndefVal(block, init_src, init)) orelse | 17673 | break :blk (try sema.resolveMaybeUndefVal(block, init_src, init)) orelse |
| 17655 | return sema.failWithNeededComptime(block, init_src); | 17674 | return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime known"); |
| 17656 | } else Value.initTag(.unreachable_value); | 17675 | } else Value.initTag(.unreachable_value); |
| 17657 | | 17676 | |
| 17658 | try sema.validateVarType(block, name_src, var_ty, small.is_extern); | 17677 | try sema.validateVarType(block, name_src, var_ty, small.is_extern); |
| ... | @@ -17718,7 +17737,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17718,7 +17737,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17718 | const body = sema.code.extra[extra_index..][0..body_len]; | 17737 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 17719 | extra_index += body.len; | 17738 | extra_index += body.len; |
| 17720 | | 17739 | |
| 17721 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29); | 17740 | const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, "alignment must be comptime known"); |
| 17722 | if (val.tag() == .generic_poison) { | 17741 | if (val.tag() == .generic_poison) { |
| 17723 | break :blk null; | 17742 | break :blk null; |
| 17724 | } | 17743 | } |
| ... | @@ -17731,7 +17750,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17731,7 +17750,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17731 | } else if (extra.data.bits.has_align_ref) blk: { | 17750 | } else if (extra.data.bits.has_align_ref) blk: { |
| 17732 | const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 17751 | const align_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 17733 | extra_index += 1; | 17752 | extra_index += 1; |
| 17734 | const align_tv = sema.resolveInstConst(block, align_src, align_ref) catch |err| switch (err) { | 17753 | const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime known") catch |err| switch (err) { |
| 17735 | error.GenericPoison => { | 17754 | error.GenericPoison => { |
| 17736 | break :blk null; | 17755 | break :blk null; |
| 17737 | }, | 17756 | }, |
| ... | @@ -17752,7 +17771,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17752,7 +17771,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17752 | extra_index += body.len; | 17771 | extra_index += body.len; |
| 17753 | | 17772 | |
| 17754 | const addrspace_ty = try sema.getBuiltinType(block, addrspace_src, "AddressSpace"); | 17773 | const addrspace_ty = try sema.getBuiltinType(block, addrspace_src, "AddressSpace"); |
| 17755 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty); | 17774 | const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime known"); |
| 17756 | if (val.tag() == .generic_poison) { | 17775 | if (val.tag() == .generic_poison) { |
| 17757 | break :blk null; | 17776 | break :blk null; |
| 17758 | } | 17777 | } |
| ... | @@ -17760,7 +17779,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17760,7 +17779,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17760 | } else if (extra.data.bits.has_addrspace_ref) blk: { | 17779 | } else if (extra.data.bits.has_addrspace_ref) blk: { |
| 17761 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 17780 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 17762 | extra_index += 1; | 17781 | extra_index += 1; |
| 17763 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref) catch |err| switch (err) { | 17782 | const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime known") catch |err| switch (err) { |
| 17764 | error.GenericPoison => { | 17783 | error.GenericPoison => { |
| 17765 | break :blk null; | 17784 | break :blk null; |
| 17766 | }, | 17785 | }, |
| ... | @@ -17775,7 +17794,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17775,7 +17794,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17775 | const body = sema.code.extra[extra_index..][0..body_len]; | 17794 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 17776 | extra_index += body.len; | 17795 | extra_index += body.len; |
| 17777 | | 17796 | |
| 17778 | const val = try sema.resolveGenericBody(block, section_src, body, inst, Type.initTag(.const_slice_u8)); | 17797 | const val = try sema.resolveGenericBody(block, section_src, body, inst, Type.initTag(.const_slice_u8), "linksection must be comptime known"); |
| 17779 | if (val.tag() == .generic_poison) { | 17798 | if (val.tag() == .generic_poison) { |
| 17780 | break :blk FuncLinkSection{ .generic = {} }; | 17799 | break :blk FuncLinkSection{ .generic = {} }; |
| 17781 | } | 17800 | } |
| ... | @@ -17784,7 +17803,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17784,7 +17803,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17784 | } else if (extra.data.bits.has_section_ref) blk: { | 17803 | } else if (extra.data.bits.has_section_ref) blk: { |
| 17785 | const section_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 17804 | const section_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 17786 | extra_index += 1; | 17805 | extra_index += 1; |
| 17787 | const section_tv = sema.resolveInstConst(block, section_src, section_ref) catch |err| switch (err) { | 17806 | const section_tv = sema.resolveInstConst(block, section_src, section_ref, "linksection must be comptime known") catch |err| switch (err) { |
| 17788 | error.GenericPoison => { | 17807 | error.GenericPoison => { |
| 17789 | break :blk FuncLinkSection{ .generic = {} }; | 17808 | break :blk FuncLinkSection{ .generic = {} }; |
| 17790 | }, | 17809 | }, |
| ... | @@ -17801,7 +17820,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17801,7 +17820,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17801 | extra_index += body.len; | 17820 | extra_index += body.len; |
| 17802 | | 17821 | |
| 17803 | const cc_ty = try sema.getBuiltinType(block, addrspace_src, "CallingConvention"); | 17822 | const cc_ty = try sema.getBuiltinType(block, addrspace_src, "CallingConvention"); |
| 17804 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty); | 17823 | const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime known"); |
| 17805 | if (val.tag() == .generic_poison) { | 17824 | if (val.tag() == .generic_poison) { |
| 17806 | break :blk null; | 17825 | break :blk null; |
| 17807 | } | 17826 | } |
| ... | @@ -17809,7 +17828,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17809,7 +17828,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17809 | } else if (extra.data.bits.has_cc_ref) blk: { | 17828 | } else if (extra.data.bits.has_cc_ref) blk: { |
| 17810 | const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 17829 | const cc_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 17811 | extra_index += 1; | 17830 | extra_index += 1; |
| 17812 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref) catch |err| switch (err) { | 17831 | const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime known") catch |err| switch (err) { |
| 17813 | error.GenericPoison => { | 17832 | error.GenericPoison => { |
| 17814 | break :blk null; | 17833 | break :blk null; |
| 17815 | }, | 17834 | }, |
| ... | @@ -17824,14 +17843,14 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -17824,14 +17843,14 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 17824 | const body = sema.code.extra[extra_index..][0..body_len]; | 17843 | const body = sema.code.extra[extra_index..][0..body_len]; |
| 17825 | extra_index += body.len; | 17844 | extra_index += body.len; |
| 17826 | | 17845 | |
| 17827 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type); | 17846 | const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, "return type must be comptime known"); |
| 17828 | var buffer: Value.ToTypeBuffer = undefined; | 17847 | var buffer: Value.ToTypeBuffer = undefined; |
| 17829 | const ty = try val.toType(&buffer).copy(sema.arena); | 17848 | const ty = try val.toType(&buffer).copy(sema.arena); |
| 17830 | break :blk ty; | 17849 | break :blk ty; |
| 17831 | } else if (extra.data.bits.has_ret_ty_ref) blk: { | 17850 | } else if (extra.data.bits.has_ret_ty_ref) blk: { |
| 17832 | const ret_ty_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | 17851 | const ret_ty_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); |
| 17833 | extra_index += 1; | 17852 | extra_index += 1; |
| 17834 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref) catch |err| switch (err) { | 17853 | const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime known") catch |err| switch (err) { |
| 17835 | error.GenericPoison => { | 17854 | error.GenericPoison => { |
| 17836 | break :blk Type.initTag(.generic_poison); | 17855 | break :blk Type.initTag(.generic_poison); |
| 17837 | }, | 17856 | }, |
| ... | @@ -17886,7 +17905,7 @@ fn zirCUndef( | ... | @@ -17886,7 +17905,7 @@ fn zirCUndef( |
| 17886 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 17905 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 17887 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 17906 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 17888 | | 17907 | |
| 17889 | const name = try sema.resolveConstString(block, src, extra.operand); | 17908 | const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime known"); |
| 17890 | try block.c_import_buf.?.writer().print("#undefine {s}\n", .{name}); | 17909 | try block.c_import_buf.?.writer().print("#undefine {s}\n", .{name}); |
| 17891 | return Air.Inst.Ref.void_value; | 17910 | return Air.Inst.Ref.void_value; |
| 17892 | } | 17911 | } |
| ... | @@ -17899,7 +17918,7 @@ fn zirCInclude( | ... | @@ -17899,7 +17918,7 @@ fn zirCInclude( |
| 17899 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 17918 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 17900 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 17919 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 17901 | | 17920 | |
| 17902 | const name = try sema.resolveConstString(block, src, extra.operand); | 17921 | const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime known"); |
| 17903 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); | 17922 | try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name}); |
| 17904 | return Air.Inst.Ref.void_value; | 17923 | return Air.Inst.Ref.void_value; |
| 17905 | } | 17924 | } |
| ... | @@ -17913,10 +17932,10 @@ fn zirCDefine( | ... | @@ -17913,10 +17932,10 @@ fn zirCDefine( |
| 17913 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 17932 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 17914 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 17933 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 17915 | | 17934 | |
| 17916 | const name = try sema.resolveConstString(block, name_src, extra.lhs); | 17935 | const name = try sema.resolveConstString(block, name_src, extra.lhs, "name of macro being undefined must be comptime known"); |
| 17917 | const rhs = try sema.resolveInst(extra.rhs); | 17936 | const rhs = try sema.resolveInst(extra.rhs); |
| 17918 | if (sema.typeOf(rhs).zigTypeTag() != .Void) { | 17937 | if (sema.typeOf(rhs).zigTypeTag() != .Void) { |
| 17919 | const value = try sema.resolveConstString(block, val_src, extra.rhs); | 17938 | const value = try sema.resolveConstString(block, val_src, extra.rhs, "value of macro being undefined must be comptime known"); |
| 17920 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); | 17939 | try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value }); |
| 17921 | } else { | 17940 | } else { |
| 17922 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); | 17941 | try block.c_import_buf.?.writer().print("#define {s}\n", .{name}); |
| ... | @@ -17937,8 +17956,8 @@ fn zirWasmMemorySize( | ... | @@ -17937,8 +17956,8 @@ fn zirWasmMemorySize( |
| 17937 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 17956 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 17938 | } | 17957 | } |
| 17939 | | 17958 | |
| 17940 | const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.operand, Type.u32)); | 17959 | const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime known")); |
| 17941 | try sema.requireRuntimeBlock(block, builtin_src); | 17960 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 17942 | return block.addInst(.{ | 17961 | return block.addInst(.{ |
| 17943 | .tag = .wasm_memory_size, | 17962 | .tag = .wasm_memory_size, |
| 17944 | .data = .{ .pl_op = .{ | 17963 | .data = .{ .pl_op = .{ |
| ... | @@ -17962,10 +17981,10 @@ fn zirWasmMemoryGrow( | ... | @@ -17962,10 +17981,10 @@ fn zirWasmMemoryGrow( |
| 17962 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 17981 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| 17963 | } | 17982 | } |
| 17964 | | 17983 | |
| 17965 | const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32)); | 17984 | const index = @intCast(u32, try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime known")); |
| 17966 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); | 17985 | const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); |
| 17967 | | 17986 | |
| 17968 | try sema.requireRuntimeBlock(block, builtin_src); | 17987 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 17969 | return block.addInst(.{ | 17988 | return block.addInst(.{ |
| 17970 | .tag = .wasm_memory_grow, | 17989 | .tag = .wasm_memory_grow, |
| 17971 | .data = .{ .pl_op = .{ | 17990 | .data = .{ .pl_op = .{ |
| ... | @@ -17990,15 +18009,15 @@ fn zirPrefetch( | ... | @@ -17990,15 +18009,15 @@ fn zirPrefetch( |
| 17990 | const target = sema.mod.getTarget(); | 18009 | const target = sema.mod.getTarget(); |
| 17991 | | 18010 | |
| 17992 | const rw = try sema.fieldVal(block, opts_src, options, "rw", opts_src); | 18011 | const rw = try sema.fieldVal(block, opts_src, options, "rw", opts_src); |
| 17993 | const rw_val = try sema.resolveConstValue(block, opts_src, rw); | 18012 | const rw_val = try sema.resolveConstValue(block, opts_src, rw, "prefetch read/write must be comptime known"); |
| 17994 | const rw_tag = rw_val.toEnum(std.builtin.PrefetchOptions.Rw); | 18013 | const rw_tag = rw_val.toEnum(std.builtin.PrefetchOptions.Rw); |
| 17995 | | 18014 | |
| 17996 | const locality = try sema.fieldVal(block, opts_src, options, "locality", opts_src); | 18015 | const locality = try sema.fieldVal(block, opts_src, options, "locality", opts_src); |
| 17997 | const locality_val = try sema.resolveConstValue(block, opts_src, locality); | 18016 | const locality_val = try sema.resolveConstValue(block, opts_src, locality, "prefetch locality must be comptime known"); |
| 17998 | const locality_int = @intCast(u2, locality_val.toUnsignedInt(target)); | 18017 | const locality_int = @intCast(u2, locality_val.toUnsignedInt(target)); |
| 17999 | | 18018 | |
| 18000 | const cache = try sema.fieldVal(block, opts_src, options, "cache", opts_src); | 18019 | const cache = try sema.fieldVal(block, opts_src, options, "cache", opts_src); |
| 18001 | const cache_val = try sema.resolveConstValue(block, opts_src, cache); | 18020 | const cache_val = try sema.resolveConstValue(block, opts_src, cache, "prefetch cache must be comptime known"); |
| 18002 | const cache_tag = cache_val.toEnum(std.builtin.PrefetchOptions.Cache); | 18021 | const cache_tag = cache_val.toEnum(std.builtin.PrefetchOptions.Cache); |
| 18003 | | 18022 | |
| 18004 | if (!block.is_comptime) { | 18023 | if (!block.is_comptime) { |
| ... | @@ -18035,16 +18054,16 @@ fn zirBuiltinExtern( | ... | @@ -18035,16 +18054,16 @@ fn zirBuiltinExtern( |
| 18035 | const options = try sema.coerce(block, extern_options_ty, options_inst, options_src); | 18054 | const options = try sema.coerce(block, extern_options_ty, options_inst, options_src); |
| 18036 | | 18055 | |
| 18037 | const name = try sema.fieldVal(block, options_src, options, "name", options_src); | 18056 | const name = try sema.fieldVal(block, options_src, options, "name", options_src); |
| 18038 | const name_val = try sema.resolveConstValue(block, options_src, name); | 18057 | const name_val = try sema.resolveConstValue(block, options_src, name, "name of the extern symbol must be comptime known"); |
| 18039 | | 18058 | |
| 18040 | const library_name_inst = try sema.fieldVal(block, options_src, options, "library_name", options_src); | 18059 | const library_name_inst = try sema.fieldVal(block, options_src, options, "library_name", options_src); |
| 18041 | const library_name_val = try sema.resolveConstValue(block, options_src, library_name_inst); | 18060 | const library_name_val = try sema.resolveConstValue(block, options_src, library_name_inst, "library in which extern symbol is must be comptime known"); |
| 18042 | | 18061 | |
| 18043 | const linkage = try sema.fieldVal(block, options_src, options, "linkage", options_src); | 18062 | const linkage = try sema.fieldVal(block, options_src, options, "linkage", options_src); |
| 18044 | const linkage_val = try sema.resolveConstValue(block, options_src, linkage); | 18063 | const linkage_val = try sema.resolveConstValue(block, options_src, linkage, "linkage of the extern symbol must be comptime known"); |
| 18045 | | 18064 | |
| 18046 | const is_thread_local = try sema.fieldVal(block, options_src, options, "is_thread_local", options_src); | 18065 | const is_thread_local = try sema.fieldVal(block, options_src, options, "is_thread_local", options_src); |
| 18047 | const is_thread_local_val = try sema.resolveConstValue(block, options_src, is_thread_local); | 18066 | const is_thread_local_val = try sema.resolveConstValue(block, options_src, is_thread_local, "threadlocality of the extern symbol must be comptime known"); |
| 18048 | | 18067 | |
| 18049 | var library_name: ?[]const u8 = null; | 18068 | var library_name: ?[]const u8 = null; |
| 18050 | if (!library_name_val.isNull()) { | 18069 | if (!library_name_val.isNull()) { |
| ... | @@ -18121,19 +18140,30 @@ fn zirBuiltinExtern( | ... | @@ -18121,19 +18140,30 @@ fn zirBuiltinExtern( |
| 18121 | new_decl.value_arena = arena_state; | 18140 | new_decl.value_arena = arena_state; |
| 18122 | | 18141 | |
| 18123 | const ref = try sema.analyzeDeclRef(new_decl_index); | 18142 | const ref = try sema.analyzeDeclRef(new_decl_index); |
| 18124 | try sema.requireRuntimeBlock(block, src); | 18143 | try sema.requireRuntimeBlock(block, src, null); |
| 18125 | return block.addBitCast(ty, ref); | 18144 | return block.addBitCast(ty, ref); |
| 18126 | } | 18145 | } |
| 18127 | | 18146 | |
| | 18147 | /// Asserts that the block is not comptime. |
| 18128 | fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | 18148 | fn requireFunctionBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| | 18149 | assert(!block.is_comptime); |
| 18129 | if (sema.func == null and !block.is_typeof and !block.is_coerce_result_ptr) { | 18150 | if (sema.func == null and !block.is_typeof and !block.is_coerce_result_ptr) { |
| 18130 | return sema.fail(block, src, "instruction illegal outside function body", .{}); | 18151 | return sema.fail(block, src, "instruction illegal outside function body", .{}); |
| 18131 | } | 18152 | } |
| 18132 | } | 18153 | } |
| 18133 | | 18154 | |
| 18134 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | 18155 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| 18135 | if (block.is_comptime) { | 18156 | if (block.is_comptime) { |
| 18136 | return sema.failWithNeededComptime(block, src); | 18157 | const msg = msg: { |
| | 18158 | const msg = try sema.errMsg(block, src, "unable to evalutate comptime expression", .{}); |
| | 18159 | errdefer msg.destroy(sema.gpa); |
| | 18160 | |
| | 18161 | if (runtime_src) |some| { |
| | 18162 | try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{}); |
| | 18163 | } |
| | 18164 | break :msg msg; |
| | 18165 | }; |
| | 18166 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18137 | } | 18167 | } |
| 18138 | try sema.requireFunctionBlock(block, src); | 18168 | try sema.requireFunctionBlock(block, src); |
| 18139 | } | 18169 | } |
| ... | @@ -18972,7 +19002,7 @@ fn fieldPtr( | ... | @@ -18972,7 +19002,7 @@ fn fieldPtr( |
| 18972 | }), | 19002 | }), |
| 18973 | ); | 19003 | ); |
| 18974 | } | 19004 | } |
| 18975 | try sema.requireRuntimeBlock(block, src); | 19005 | try sema.requireRuntimeBlock(block, src, null); |
| 18976 | | 19006 | |
| 18977 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); | 19007 | return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr); |
| 18978 | } else if (mem.eql(u8, field_name, "len")) { | 19008 | } else if (mem.eql(u8, field_name, "len")) { |
| ... | @@ -18992,7 +19022,7 @@ fn fieldPtr( | ... | @@ -18992,7 +19022,7 @@ fn fieldPtr( |
| 18992 | }), | 19022 | }), |
| 18993 | ); | 19023 | ); |
| 18994 | } | 19024 | } |
| 18995 | try sema.requireRuntimeBlock(block, src); | 19025 | try sema.requireRuntimeBlock(block, src, null); |
| 18996 | | 19026 | |
| 18997 | return block.addTyOp(.ptr_slice_len_ptr, result_ty, inner_ptr); | 19027 | return block.addTyOp(.ptr_slice_len_ptr, result_ty, inner_ptr); |
| 18998 | } else { | 19028 | } else { |
| ... | @@ -19005,7 +19035,7 @@ fn fieldPtr( | ... | @@ -19005,7 +19035,7 @@ fn fieldPtr( |
| 19005 | } | 19035 | } |
| 19006 | }, | 19036 | }, |
| 19007 | .Type => { | 19037 | .Type => { |
| 19008 | _ = try sema.resolveConstValue(block, object_ptr_src, object_ptr); | 19038 | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined); |
| 19009 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); | 19039 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 19010 | const inner = if (is_pointer_to) | 19040 | const inner = if (is_pointer_to) |
| 19011 | try sema.analyzeLoad(block, src, result, object_ptr_src) | 19041 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | @@ -19238,7 +19268,7 @@ fn finishFieldCallBind( | ... | @@ -19238,7 +19268,7 @@ fn finishFieldCallBind( |
| 19238 | return sema.analyzeLoad(block, src, pointer, src); | 19268 | return sema.analyzeLoad(block, src, pointer, src); |
| 19239 | } | 19269 | } |
| 19240 | | 19270 | |
| 19241 | try sema.requireRuntimeBlock(block, src); | 19271 | try sema.requireRuntimeBlock(block, src, null); |
| 19242 | const ptr_inst = try block.addStructFieldPtr(object_ptr, field_index, ptr_field_ty); | 19272 | const ptr_inst = try block.addStructFieldPtr(object_ptr, field_index, ptr_field_ty); |
| 19243 | return sema.analyzeLoad(block, src, ptr_inst, src); | 19273 | return sema.analyzeLoad(block, src, ptr_inst, src); |
| 19244 | } | 19274 | } |
| ... | @@ -19425,7 +19455,7 @@ fn structFieldPtrByIndex( | ... | @@ -19425,7 +19455,7 @@ fn structFieldPtrByIndex( |
| 19425 | ); | 19455 | ); |
| 19426 | } | 19456 | } |
| 19427 | | 19457 | |
| 19428 | try sema.requireRuntimeBlock(block, src); | 19458 | try sema.requireRuntimeBlock(block, src, null); |
| 19429 | return block.addStructFieldPtr(struct_ptr, field_index, ptr_field_ty); | 19459 | return block.addStructFieldPtr(struct_ptr, field_index, ptr_field_ty); |
| 19430 | } | 19460 | } |
| 19431 | | 19461 | |
| ... | @@ -19469,7 +19499,7 @@ fn structFieldVal( | ... | @@ -19469,7 +19499,7 @@ fn structFieldVal( |
| 19469 | return sema.addConstant(field.ty, field_values[field_index]); | 19499 | return sema.addConstant(field.ty, field_values[field_index]); |
| 19470 | } | 19500 | } |
| 19471 | | 19501 | |
| 19472 | try sema.requireRuntimeBlock(block, src); | 19502 | try sema.requireRuntimeBlock(block, src, null); |
| 19473 | return block.addStructFieldVal(struct_byval, field_index, field.ty); | 19503 | return block.addStructFieldVal(struct_byval, field_index, field.ty); |
| 19474 | }, | 19504 | }, |
| 19475 | else => unreachable, | 19505 | else => unreachable, |
| ... | @@ -19533,7 +19563,7 @@ fn tupleFieldValByIndex( | ... | @@ -19533,7 +19563,7 @@ fn tupleFieldValByIndex( |
| 19533 | return sema.addConstant(field_ty, field_values[field_index]); | 19563 | return sema.addConstant(field_ty, field_values[field_index]); |
| 19534 | } | 19564 | } |
| 19535 | | 19565 | |
| 19536 | try sema.requireRuntimeBlock(block, src); | 19566 | try sema.requireRuntimeBlock(block, src, null); |
| 19537 | return block.addStructFieldVal(tuple_byval, field_index, field_ty); | 19567 | return block.addStructFieldVal(tuple_byval, field_index, field_ty); |
| 19538 | } | 19568 | } |
| 19539 | | 19569 | |
| ... | @@ -19597,7 +19627,7 @@ fn unionFieldPtr( | ... | @@ -19597,7 +19627,7 @@ fn unionFieldPtr( |
| 19597 | ); | 19627 | ); |
| 19598 | } | 19628 | } |
| 19599 | | 19629 | |
| 19600 | try sema.requireRuntimeBlock(block, src); | 19630 | try sema.requireRuntimeBlock(block, src, null); |
| 19601 | return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty); | 19631 | return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty); |
| 19602 | } | 19632 | } |
| 19603 | | 19633 | |
| ... | @@ -19655,7 +19685,7 @@ fn unionFieldVal( | ... | @@ -19655,7 +19685,7 @@ fn unionFieldVal( |
| 19655 | } | 19685 | } |
| 19656 | } | 19686 | } |
| 19657 | | 19687 | |
| 19658 | try sema.requireRuntimeBlock(block, src); | 19688 | try sema.requireRuntimeBlock(block, src, null); |
| 19659 | return block.addStructFieldVal(union_byval, field_index, field.ty); | 19689 | return block.addStructFieldVal(union_byval, field_index, field.ty); |
| 19660 | } | 19690 | } |
| 19661 | | 19691 | |
| ... | @@ -19684,7 +19714,7 @@ fn elemPtr( | ... | @@ -19684,7 +19714,7 @@ fn elemPtr( |
| 19684 | // In all below cases, we have to deref the ptr operand to get the actual indexable pointer. | 19714 | // In all below cases, we have to deref the ptr operand to get the actual indexable pointer. |
| 19685 | const indexable = try sema.analyzeLoad(block, indexable_ptr_src, indexable_ptr, indexable_ptr_src); | 19715 | const indexable = try sema.analyzeLoad(block, indexable_ptr_src, indexable_ptr, indexable_ptr_src); |
| 19686 | switch (indexable_ty.ptrSize()) { | 19716 | switch (indexable_ty.ptrSize()) { |
| 19687 | .Slice => return sema.elemPtrSlice(block, indexable_ptr_src, indexable, elem_index_src, elem_index), | 19717 | .Slice => return sema.elemPtrSlice(block, src, indexable_ptr_src, indexable, elem_index_src, elem_index), |
| 19688 | .Many, .C => { | 19718 | .Many, .C => { |
| 19689 | const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_ptr_src, indexable); | 19719 | const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_ptr_src, indexable); |
| 19690 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 19720 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| ... | @@ -19698,19 +19728,19 @@ fn elemPtr( | ... | @@ -19698,19 +19728,19 @@ fn elemPtr( |
| 19698 | }; | 19728 | }; |
| 19699 | const result_ty = try sema.elemPtrType(indexable_ty, null); | 19729 | const result_ty = try sema.elemPtrType(indexable_ty, null); |
| 19700 | | 19730 | |
| 19701 | try sema.requireRuntimeBlock(block, runtime_src); | 19731 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 19702 | return block.addPtrElemPtr(indexable, elem_index, result_ty); | 19732 | return block.addPtrElemPtr(indexable, elem_index, result_ty); |
| 19703 | }, | 19733 | }, |
| 19704 | .One => { | 19734 | .One => { |
| 19705 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable | 19735 | assert(indexable_ty.childType().zigTypeTag() == .Array); // Guaranteed by isIndexable |
| 19706 | return sema.elemPtrArray(block, indexable_ptr_src, indexable, elem_index_src, elem_index, init); | 19736 | return sema.elemPtrArray(block, src, indexable_ptr_src, indexable, elem_index_src, elem_index, init); |
| 19707 | }, | 19737 | }, |
| 19708 | } | 19738 | } |
| 19709 | }, | 19739 | }, |
| 19710 | .Array, .Vector => return sema.elemPtrArray(block, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init), | 19740 | .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init), |
| 19711 | .Struct => { | 19741 | .Struct => { |
| 19712 | // Tuple field access. | 19742 | // Tuple field access. |
| 19713 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index); | 19743 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime known"); |
| 19714 | const index = @intCast(u32, index_val.toUnsignedInt(target)); | 19744 | const index = @intCast(u32, index_val.toUnsignedInt(target)); |
| 19715 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index); | 19745 | return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index); |
| 19716 | }, | 19746 | }, |
| ... | @@ -19740,7 +19770,7 @@ fn elemVal( | ... | @@ -19740,7 +19770,7 @@ fn elemVal( |
| 19740 | | 19770 | |
| 19741 | switch (indexable_ty.zigTypeTag()) { | 19771 | switch (indexable_ty.zigTypeTag()) { |
| 19742 | .Pointer => switch (indexable_ty.ptrSize()) { | 19772 | .Pointer => switch (indexable_ty.ptrSize()) { |
| 19743 | .Slice => return sema.elemValSlice(block, indexable_src, indexable, elem_index_src, elem_index), | 19773 | .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index), |
| 19744 | .Many, .C => { | 19774 | .Many, .C => { |
| 19745 | const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable); | 19775 | const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable); |
| 19746 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); | 19776 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| ... | @@ -19756,7 +19786,7 @@ fn elemVal( | ... | @@ -19756,7 +19786,7 @@ fn elemVal( |
| 19756 | break :rs indexable_src; | 19786 | break :rs indexable_src; |
| 19757 | }; | 19787 | }; |
| 19758 | | 19788 | |
| 19759 | try sema.requireRuntimeBlock(block, runtime_src); | 19789 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 19760 | return block.addBinOp(.ptr_elem_val, indexable, elem_index); | 19790 | return block.addBinOp(.ptr_elem_val, indexable, elem_index); |
| 19761 | }, | 19791 | }, |
| 19762 | .One => { | 19792 | .One => { |
| ... | @@ -19765,14 +19795,14 @@ fn elemVal( | ... | @@ -19765,14 +19795,14 @@ fn elemVal( |
| 19765 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); | 19795 | return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src); |
| 19766 | }, | 19796 | }, |
| 19767 | }, | 19797 | }, |
| 19768 | .Array => return elemValArray(sema, block, indexable_src, indexable, elem_index_src, elem_index), | 19798 | .Array => return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index), |
| 19769 | .Vector => { | 19799 | .Vector => { |
| 19770 | // TODO: If the index is a vector, the result should be a vector. | 19800 | // TODO: If the index is a vector, the result should be a vector. |
| 19771 | return elemValArray(sema, block, indexable_src, indexable, elem_index_src, elem_index); | 19801 | return sema.elemValArray(block, src, indexable_src, indexable, elem_index_src, elem_index); |
| 19772 | }, | 19802 | }, |
| 19773 | .Struct => { | 19803 | .Struct => { |
| 19774 | // Tuple field access. | 19804 | // Tuple field access. |
| 19775 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index); | 19805 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime known"); |
| 19776 | const index = @intCast(u32, index_val.toUnsignedInt(target)); | 19806 | const index = @intCast(u32, index_val.toUnsignedInt(target)); |
| 19777 | return tupleField(sema, block, indexable_src, indexable, elem_index_src, index); | 19807 | return tupleField(sema, block, indexable_src, indexable, elem_index_src, index); |
| 19778 | }, | 19808 | }, |
| ... | @@ -19850,7 +19880,7 @@ fn tupleFieldPtr( | ... | @@ -19850,7 +19880,7 @@ fn tupleFieldPtr( |
| 19850 | | 19880 | |
| 19851 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_ptr_src); | 19881 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_ptr_src); |
| 19852 | | 19882 | |
| 19853 | try sema.requireRuntimeBlock(block, tuple_ptr_src); | 19883 | try sema.requireRuntimeBlock(block, tuple_ptr_src, null); |
| 19854 | return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty); | 19884 | return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty); |
| 19855 | } | 19885 | } |
| 19856 | | 19886 | |
| ... | @@ -19890,13 +19920,14 @@ fn tupleField( | ... | @@ -19890,13 +19920,14 @@ fn tupleField( |
| 19890 | | 19920 | |
| 19891 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src); | 19921 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src); |
| 19892 | | 19922 | |
| 19893 | try sema.requireRuntimeBlock(block, tuple_src); | 19923 | try sema.requireRuntimeBlock(block, tuple_src, null); |
| 19894 | return block.addStructFieldVal(tuple, field_index, field_ty); | 19924 | return block.addStructFieldVal(tuple, field_index, field_ty); |
| 19895 | } | 19925 | } |
| 19896 | | 19926 | |
| 19897 | fn elemValArray( | 19927 | fn elemValArray( |
| 19898 | sema: *Sema, | 19928 | sema: *Sema, |
| 19899 | block: *Block, | 19929 | block: *Block, |
| | 19930 | src: LazySrcLoc, |
| 19900 | array_src: LazySrcLoc, | 19931 | array_src: LazySrcLoc, |
| 19901 | array: Air.Inst.Ref, | 19932 | array: Air.Inst.Ref, |
| 19902 | elem_index_src: LazySrcLoc, | 19933 | elem_index_src: LazySrcLoc, |
| ... | @@ -19943,7 +19974,7 @@ fn elemValArray( | ... | @@ -19943,7 +19974,7 @@ fn elemValArray( |
| 19943 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, array_ty, array_src); | 19974 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, array_ty, array_src); |
| 19944 | | 19975 | |
| 19945 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; | 19976 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; |
| 19946 | try sema.requireRuntimeBlock(block, runtime_src); | 19977 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 19947 | if (block.wantSafety()) { | 19978 | if (block.wantSafety()) { |
| 19948 | // Runtime check is only needed if unable to comptime check | 19979 | // Runtime check is only needed if unable to comptime check |
| 19949 | if (maybe_index_val == null) { | 19980 | if (maybe_index_val == null) { |
| ... | @@ -19958,6 +19989,7 @@ fn elemValArray( | ... | @@ -19958,6 +19989,7 @@ fn elemValArray( |
| 19958 | fn elemPtrArray( | 19989 | fn elemPtrArray( |
| 19959 | sema: *Sema, | 19990 | sema: *Sema, |
| 19960 | block: *Block, | 19991 | block: *Block, |
| | 19992 | src: LazySrcLoc, |
| 19961 | array_ptr_src: LazySrcLoc, | 19993 | array_ptr_src: LazySrcLoc, |
| 19962 | array_ptr: Air.Inst.Ref, | 19994 | array_ptr: Air.Inst.Ref, |
| 19963 | elem_index_src: LazySrcLoc, | 19995 | elem_index_src: LazySrcLoc, |
| ... | @@ -20003,7 +20035,7 @@ fn elemPtrArray( | ... | @@ -20003,7 +20035,7 @@ fn elemPtrArray( |
| 20003 | } | 20035 | } |
| 20004 | | 20036 | |
| 20005 | const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src; | 20037 | const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src; |
| 20006 | try sema.requireRuntimeBlock(block, runtime_src); | 20038 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 20007 | | 20039 | |
| 20008 | // Runtime check is only needed if unable to comptime check. | 20040 | // Runtime check is only needed if unable to comptime check. |
| 20009 | if (block.wantSafety() and offset == null) { | 20041 | if (block.wantSafety() and offset == null) { |
| ... | @@ -20018,6 +20050,7 @@ fn elemPtrArray( | ... | @@ -20018,6 +20050,7 @@ fn elemPtrArray( |
| 20018 | fn elemValSlice( | 20050 | fn elemValSlice( |
| 20019 | sema: *Sema, | 20051 | sema: *Sema, |
| 20020 | block: *Block, | 20052 | block: *Block, |
| | 20053 | src: LazySrcLoc, |
| 20021 | slice_src: LazySrcLoc, | 20054 | slice_src: LazySrcLoc, |
| 20022 | slice: Air.Inst.Ref, | 20055 | slice: Air.Inst.Ref, |
| 20023 | elem_index_src: LazySrcLoc, | 20056 | elem_index_src: LazySrcLoc, |
| ... | @@ -20057,7 +20090,7 @@ fn elemValSlice( | ... | @@ -20057,7 +20090,7 @@ fn elemValSlice( |
| 20057 | | 20090 | |
| 20058 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src); | 20091 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src); |
| 20059 | | 20092 | |
| 20060 | try sema.requireRuntimeBlock(block, runtime_src); | 20093 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 20061 | if (block.wantSafety()) { | 20094 | if (block.wantSafety()) { |
| 20062 | const len_inst = if (maybe_slice_val) |slice_val| | 20095 | const len_inst = if (maybe_slice_val) |slice_val| |
| 20063 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)) | 20096 | try sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)) |
| ... | @@ -20073,6 +20106,7 @@ fn elemValSlice( | ... | @@ -20073,6 +20106,7 @@ fn elemValSlice( |
| 20073 | fn elemPtrSlice( | 20106 | fn elemPtrSlice( |
| 20074 | sema: *Sema, | 20107 | sema: *Sema, |
| 20075 | block: *Block, | 20108 | block: *Block, |
| | 20109 | src: LazySrcLoc, |
| 20076 | slice_src: LazySrcLoc, | 20110 | slice_src: LazySrcLoc, |
| 20077 | slice: Air.Inst.Ref, | 20111 | slice: Air.Inst.Ref, |
| 20078 | elem_index_src: LazySrcLoc, | 20112 | elem_index_src: LazySrcLoc, |
| ... | @@ -20113,7 +20147,7 @@ fn elemPtrSlice( | ... | @@ -20113,7 +20147,7 @@ fn elemPtrSlice( |
| 20113 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ptr_ty, slice_ty, slice_src); | 20147 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ptr_ty, slice_ty, slice_src); |
| 20114 | | 20148 | |
| 20115 | const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src; | 20149 | const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src; |
| 20116 | try sema.requireRuntimeBlock(block, runtime_src); | 20150 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 20117 | if (block.wantSafety()) { | 20151 | if (block.wantSafety()) { |
| 20118 | const len_inst = len: { | 20152 | const len_inst = len: { |
| 20119 | if (maybe_undef_slice_val) |slice_val| | 20153 | if (maybe_undef_slice_val) |slice_val| |
| ... | @@ -20177,7 +20211,7 @@ fn coerceExtra( | ... | @@ -20177,7 +20211,7 @@ fn coerceExtra( |
| 20177 | // Keep the comptime Value representation; take the new type. | 20211 | // Keep the comptime Value representation; take the new type. |
| 20178 | return sema.addConstant(dest_ty, val); | 20212 | return sema.addConstant(dest_ty, val); |
| 20179 | } | 20213 | } |
| 20180 | try sema.requireRuntimeBlock(block, inst_src); | 20214 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 20181 | return block.addBitCast(dest_ty, inst); | 20215 | return block.addBitCast(dest_ty, inst); |
| 20182 | } | 20216 | } |
| 20183 | | 20217 | |
| ... | @@ -20222,7 +20256,7 @@ fn coerceExtra( | ... | @@ -20222,7 +20256,7 @@ fn coerceExtra( |
| 20222 | | 20256 | |
| 20223 | // Function body to function pointer. | 20257 | // Function body to function pointer. |
| 20224 | if (inst_ty.zigTypeTag() == .Fn) { | 20258 | if (inst_ty.zigTypeTag() == .Fn) { |
| 20225 | const fn_val = try sema.resolveConstValue(block, inst_src, inst); | 20259 | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 20226 | const fn_decl = fn_val.castTag(.function).?.data.owner_decl; | 20260 | const fn_decl = fn_val.castTag(.function).?.data.owner_decl; |
| 20227 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); | 20261 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 20228 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); | 20262 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | @@ -20489,7 +20523,7 @@ fn coerceExtra( | ... | @@ -20489,7 +20523,7 @@ fn coerceExtra( |
| 20489 | // small enough unsigned ints can get casted to large enough signed ints | 20523 | // small enough unsigned ints can get casted to large enough signed ints |
| 20490 | (dst_info.signedness == .signed and dst_info.bits > src_info.bits)) | 20524 | (dst_info.signedness == .signed and dst_info.bits > src_info.bits)) |
| 20491 | { | 20525 | { |
| 20492 | try sema.requireRuntimeBlock(block, inst_src); | 20526 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 20493 | return block.addTyOp(.intcast, dest_ty, inst); | 20527 | return block.addTyOp(.intcast, dest_ty, inst); |
| 20494 | } | 20528 | } |
| 20495 | }, | 20529 | }, |
| ... | @@ -20500,7 +20534,7 @@ fn coerceExtra( | ... | @@ -20500,7 +20534,7 @@ fn coerceExtra( |
| 20500 | }, | 20534 | }, |
| 20501 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag()) { | 20535 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag()) { |
| 20502 | .ComptimeFloat => { | 20536 | .ComptimeFloat => { |
| 20503 | const val = try sema.resolveConstValue(block, inst_src, inst); | 20537 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 20504 | const result_val = try val.floatCast(sema.arena, dest_ty, target); | 20538 | const result_val = try val.floatCast(sema.arena, dest_ty, target); |
| 20505 | return try sema.addConstant(dest_ty, result_val); | 20539 | return try sema.addConstant(dest_ty, result_val); |
| 20506 | }, | 20540 | }, |
| ... | @@ -20516,13 +20550,15 @@ fn coerceExtra( | ... | @@ -20516,13 +20550,15 @@ fn coerceExtra( |
| 20516 | ); | 20550 | ); |
| 20517 | } | 20551 | } |
| 20518 | return try sema.addConstant(dest_ty, result_val); | 20552 | return try sema.addConstant(dest_ty, result_val); |
| | 20553 | } else if (dest_ty.zigTypeTag() == .ComptimeFloat) { |
| | 20554 | return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime known"); |
| 20519 | } | 20555 | } |
| 20520 | | 20556 | |
| 20521 | // float widening | 20557 | // float widening |
| 20522 | const src_bits = inst_ty.floatBits(target); | 20558 | const src_bits = inst_ty.floatBits(target); |
| 20523 | const dst_bits = dest_ty.floatBits(target); | 20559 | const dst_bits = dest_ty.floatBits(target); |
| 20524 | if (dst_bits >= src_bits) { | 20560 | if (dst_bits >= src_bits) { |
| 20525 | try sema.requireRuntimeBlock(block, inst_src); | 20561 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 20526 | return block.addTyOp(.fpext, dest_ty, inst); | 20562 | return block.addTyOp(.fpext, dest_ty, inst); |
| 20527 | } | 20563 | } |
| 20528 | }, | 20564 | }, |
| ... | @@ -20549,7 +20585,7 @@ fn coerceExtra( | ... | @@ -20549,7 +20585,7 @@ fn coerceExtra( |
| 20549 | .Enum => switch (inst_ty.zigTypeTag()) { | 20585 | .Enum => switch (inst_ty.zigTypeTag()) { |
| 20550 | .EnumLiteral => { | 20586 | .EnumLiteral => { |
| 20551 | // enum literal to enum | 20587 | // enum literal to enum |
| 20552 | const val = try sema.resolveConstValue(block, inst_src, inst); | 20588 | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 20553 | const bytes = val.castTag(.enum_literal).?.data; | 20589 | const bytes = val.castTag(.enum_literal).?.data; |
| 20554 | const field_index = dest_ty.enumFieldIndex(bytes) orelse { | 20590 | const field_index = dest_ty.enumFieldIndex(bytes) orelse { |
| 20555 | const msg = msg: { | 20591 | const msg = msg: { |
| ... | @@ -21712,7 +21748,12 @@ fn storePtr2( | ... | @@ -21712,7 +21748,12 @@ fn storePtr2( |
| 21712 | return; | 21748 | return; |
| 21713 | } | 21749 | } |
| 21714 | | 21750 | |
| 21715 | try sema.requireRuntimeBlock(block, runtime_src); | 21751 | if (block.is_comptime) { |
| | 21752 | // TODO ideally this would tell why the block is comptime |
| | 21753 | return sema.fail(block, ptr_src, "cannot store to runtime value in comptime block", .{}); |
| | 21754 | } |
| | 21755 | |
| | 21756 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 21716 | try sema.queueFullTypeResolution(elem_ty); | 21757 | try sema.queueFullTypeResolution(elem_ty); |
| 21717 | if (is_ret) { | 21758 | if (is_ret) { |
| 21718 | _ = try block.addBinOp(.store, ptr, operand); | 21759 | _ = try block.addBinOp(.store, ptr, operand); |
| ... | @@ -22644,7 +22685,7 @@ fn bitCast( | ... | @@ -22644,7 +22685,7 @@ fn bitCast( |
| 22644 | const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0); | 22685 | const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0); |
| 22645 | return sema.addConstant(dest_ty, result_val); | 22686 | return sema.addConstant(dest_ty, result_val); |
| 22646 | } | 22687 | } |
| 22647 | try sema.requireRuntimeBlock(block, inst_src); | 22688 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 22648 | return block.addBitCast(dest_ty, inst); | 22689 | return block.addBitCast(dest_ty, inst); |
| 22649 | } | 22690 | } |
| 22650 | | 22691 | |
| ... | @@ -22727,7 +22768,7 @@ fn coerceArrayPtrToSlice( | ... | @@ -22727,7 +22768,7 @@ fn coerceArrayPtrToSlice( |
| 22727 | }); | 22768 | }); |
| 22728 | return sema.addConstant(dest_ty, slice_val); | 22769 | return sema.addConstant(dest_ty, slice_val); |
| 22729 | } | 22770 | } |
| 22730 | try sema.requireRuntimeBlock(block, inst_src); | 22771 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 22731 | return block.addTyOp(.array_to_slice, dest_ty, inst); | 22772 | return block.addTyOp(.array_to_slice, dest_ty, inst); |
| 22732 | } | 22773 | } |
| 22733 | | 22774 | |
| ... | @@ -22743,7 +22784,7 @@ fn coerceCompatiblePtrs( | ... | @@ -22743,7 +22784,7 @@ fn coerceCompatiblePtrs( |
| 22743 | // The comptime Value representation is compatible with both types. | 22784 | // The comptime Value representation is compatible with both types. |
| 22744 | return sema.addConstant(dest_ty, val); | 22785 | return sema.addConstant(dest_ty, val); |
| 22745 | } | 22786 | } |
| 22746 | try sema.requireRuntimeBlock(block, inst_src); | 22787 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 22747 | return sema.bitCast(block, dest_ty, inst, inst_src); | 22788 | return sema.bitCast(block, dest_ty, inst, inst_src); |
| 22748 | } | 22789 | } |
| 22749 | | 22790 | |
| ... | @@ -22807,7 +22848,7 @@ fn coerceEnumToUnion( | ... | @@ -22807,7 +22848,7 @@ fn coerceEnumToUnion( |
| 22807 | })); | 22848 | })); |
| 22808 | } | 22849 | } |
| 22809 | | 22850 | |
| 22810 | try sema.requireRuntimeBlock(block, inst_src); | 22851 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 22811 | | 22852 | |
| 22812 | if (tag_ty.isNonexhaustiveEnum()) { | 22853 | if (tag_ty.isNonexhaustiveEnum()) { |
| 22813 | const msg = msg: { | 22854 | const msg = msg: { |
| ... | @@ -22947,7 +22988,7 @@ fn coerceArrayLike( | ... | @@ -22947,7 +22988,7 @@ fn coerceArrayLike( |
| 22947 | // These types share the same comptime value representation. | 22988 | // These types share the same comptime value representation. |
| 22948 | return sema.addConstant(dest_ty, inst_val); | 22989 | return sema.addConstant(dest_ty, inst_val); |
| 22949 | } | 22990 | } |
| 22950 | try sema.requireRuntimeBlock(block, inst_src); | 22991 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 22951 | return block.addBitCast(dest_ty, inst); | 22992 | return block.addBitCast(dest_ty, inst); |
| 22952 | } | 22993 | } |
| 22953 | | 22994 | |
| ... | @@ -22960,8 +23001,9 @@ fn coerceArrayLike( | ... | @@ -22960,8 +23001,9 @@ fn coerceArrayLike( |
| 22960 | Type.usize, | 23001 | Type.usize, |
| 22961 | try Value.Tag.int_u64.create(sema.arena, i), | 23002 | try Value.Tag.int_u64.create(sema.arena, i), |
| 22962 | ); | 23003 | ); |
| | 23004 | const src = inst_src; // TODO better source location |
| 22963 | const elem_src = inst_src; // TODO better source location | 23005 | const elem_src = inst_src; // TODO better source location |
| 22964 | const elem_ref = try elemValArray(sema, block, inst_src, inst, elem_src, index_ref); | 23006 | const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref); |
| 22965 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); | 23007 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 22966 | element_refs[i] = coerced; | 23008 | element_refs[i] = coerced; |
| 22967 | if (runtime_src == null) { | 23009 | if (runtime_src == null) { |
| ... | @@ -22974,7 +23016,7 @@ fn coerceArrayLike( | ... | @@ -22974,7 +23016,7 @@ fn coerceArrayLike( |
| 22974 | } | 23016 | } |
| 22975 | | 23017 | |
| 22976 | if (runtime_src) |rs| { | 23018 | if (runtime_src) |rs| { |
| 22977 | try sema.requireRuntimeBlock(block, rs); | 23019 | try sema.requireRuntimeBlock(block, inst_src, rs); |
| 22978 | return block.addAggregateInit(dest_ty, element_refs); | 23020 | return block.addAggregateInit(dest_ty, element_refs); |
| 22979 | } | 23021 | } |
| 22980 | | 23022 | |
| ... | @@ -23037,7 +23079,7 @@ fn coerceTupleToArray( | ... | @@ -23037,7 +23079,7 @@ fn coerceTupleToArray( |
| 23037 | } | 23079 | } |
| 23038 | | 23080 | |
| 23039 | if (runtime_src) |rs| { | 23081 | if (runtime_src) |rs| { |
| 23040 | try sema.requireRuntimeBlock(block, rs); | 23082 | try sema.requireRuntimeBlock(block, inst_src, rs); |
| 23041 | return block.addAggregateInit(dest_ty, element_refs); | 23083 | return block.addAggregateInit(dest_ty, element_refs); |
| 23042 | } | 23084 | } |
| 23043 | | 23085 | |
| ... | @@ -23168,7 +23210,7 @@ fn coerceTupleToStruct( | ... | @@ -23168,7 +23210,7 @@ fn coerceTupleToStruct( |
| 23168 | } | 23210 | } |
| 23169 | | 23211 | |
| 23170 | if (runtime_src) |rs| { | 23212 | if (runtime_src) |rs| { |
| 23171 | try sema.requireRuntimeBlock(block, rs); | 23213 | try sema.requireRuntimeBlock(block, inst_src, rs); |
| 23172 | return block.addAggregateInit(struct_ty, field_refs); | 23214 | return block.addAggregateInit(struct_ty, field_refs); |
| 23173 | } | 23215 | } |
| 23174 | | 23216 | |
| ... | @@ -23282,7 +23324,7 @@ fn analyzeRef( | ... | @@ -23282,7 +23324,7 @@ fn analyzeRef( |
| 23282 | )); | 23324 | )); |
| 23283 | } | 23325 | } |
| 23284 | | 23326 | |
| 23285 | try sema.requireRuntimeBlock(block, src); | 23327 | try sema.requireRuntimeBlock(block, src, null); |
| 23286 | const address_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); | 23328 | const address_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); |
| 23287 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ | 23329 | const ptr_type = try Type.ptr(sema.arena, sema.mod, .{ |
| 23288 | .pointee_type = operand_ty, | 23330 | .pointee_type = operand_ty, |
| ... | @@ -23326,10 +23368,12 @@ fn analyzeLoad( | ... | @@ -23326,10 +23368,12 @@ fn analyzeLoad( |
| 23326 | } | 23368 | } |
| 23327 | } | 23369 | } |
| 23328 | | 23370 | |
| 23329 | const valid_rt = try sema.validateRunTimeType(block, src, elem_ty, false); | 23371 | if (block.is_comptime) { |
| 23330 | if (!valid_rt) return sema.failWithNeededComptime(block, src); | 23372 | // TODO ideally this would tell why the block is comptime |
| | 23373 | return sema.fail(block, ptr_src, "cannot load runtime value in comptime block", .{}); |
| | 23374 | } |
| 23331 | | 23375 | |
| 23332 | try sema.requireRuntimeBlock(block, src); | 23376 | try sema.requireFunctionBlock(block, src); |
| 23333 | return block.addTyOp(.load, elem_ty, ptr); | 23377 | return block.addTyOp(.load, elem_ty, ptr); |
| 23334 | } | 23378 | } |
| 23335 | | 23379 | |
| ... | @@ -23346,7 +23390,7 @@ fn analyzeSlicePtr( | ... | @@ -23346,7 +23390,7 @@ fn analyzeSlicePtr( |
| 23346 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 23390 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 23347 | return sema.addConstant(result_ty, val.slicePtr()); | 23391 | return sema.addConstant(result_ty, val.slicePtr()); |
| 23348 | } | 23392 | } |
| 23349 | try sema.requireRuntimeBlock(block, slice_src); | 23393 | try sema.requireRuntimeBlock(block, slice_src, null); |
| 23350 | return block.addTyOp(.slice_ptr, result_ty, slice); | 23394 | return block.addTyOp(.slice_ptr, result_ty, slice); |
| 23351 | } | 23395 | } |
| 23352 | | 23396 | |
| ... | @@ -23362,7 +23406,7 @@ fn analyzeSliceLen( | ... | @@ -23362,7 +23406,7 @@ fn analyzeSliceLen( |
| 23362 | } | 23406 | } |
| 23363 | return sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)); | 23407 | return sema.addIntUnsigned(Type.usize, slice_val.sliceLen(sema.mod)); |
| 23364 | } | 23408 | } |
| 23365 | try sema.requireRuntimeBlock(block, src); | 23409 | try sema.requireRuntimeBlock(block, src, null); |
| 23366 | return block.addTyOp(.slice_len, Type.usize, slice_inst); | 23410 | return block.addTyOp(.slice_len, Type.usize, slice_inst); |
| 23367 | } | 23411 | } |
| 23368 | | 23412 | |
| ... | @@ -23386,7 +23430,7 @@ fn analyzeIsNull( | ... | @@ -23386,7 +23430,7 @@ fn analyzeIsNull( |
| 23386 | return Air.Inst.Ref.bool_false; | 23430 | return Air.Inst.Ref.bool_false; |
| 23387 | } | 23431 | } |
| 23388 | } | 23432 | } |
| 23389 | try sema.requireRuntimeBlock(block, src); | 23433 | try sema.requireRuntimeBlock(block, src, null); |
| 23390 | const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null; | 23434 | const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null; |
| 23391 | return block.addUnOp(air_tag, operand); | 23435 | return block.addUnOp(air_tag, operand); |
| 23392 | } | 23436 | } |
| ... | @@ -23476,7 +23520,7 @@ fn analyzeIsNonErr( | ... | @@ -23476,7 +23520,7 @@ fn analyzeIsNonErr( |
| 23476 | ) CompileError!Air.Inst.Ref { | 23520 | ) CompileError!Air.Inst.Ref { |
| 23477 | const result = try sema.analyzeIsNonErrComptimeOnly(block, src, operand); | 23521 | const result = try sema.analyzeIsNonErrComptimeOnly(block, src, operand); |
| 23478 | if (result == .none) { | 23522 | if (result == .none) { |
| 23479 | try sema.requireRuntimeBlock(block, src); | 23523 | try sema.requireRuntimeBlock(block, src, null); |
| 23480 | return block.addUnOp(.is_non_err, operand); | 23524 | return block.addUnOp(.is_non_err, operand); |
| 23481 | } else { | 23525 | } else { |
| 23482 | return result; | 23526 | return result; |
| ... | @@ -23661,7 +23705,7 @@ fn analyzeSlice( | ... | @@ -23661,7 +23705,7 @@ fn analyzeSlice( |
| 23661 | const sentinel = s: { | 23705 | const sentinel = s: { |
| 23662 | if (sentinel_opt != .none) { | 23706 | if (sentinel_opt != .none) { |
| 23663 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); | 23707 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 23664 | break :s try sema.resolveConstValue(block, sentinel_src, casted); | 23708 | break :s try sema.resolveConstValue(block, sentinel_src, casted, "slice sentinel must be comptime known"); |
| 23665 | } | 23709 | } |
| 23666 | // If we are slicing to the end of something that is sentinel-terminated | 23710 | // If we are slicing to the end of something that is sentinel-terminated |
| 23667 | // then the resulting slice type is also sentinel-terminated. | 23711 | // then the resulting slice type is also sentinel-terminated. |
| ... | @@ -23738,7 +23782,14 @@ fn analyzeSlice( | ... | @@ -23738,7 +23782,14 @@ fn analyzeSlice( |
| 23738 | .size = .Slice, | 23782 | .size = .Slice, |
| 23739 | }); | 23783 | }); |
| 23740 | | 23784 | |
| 23741 | try sema.requireRuntimeBlock(block, src); | 23785 | const runtime_src = if ((try sema.resolveMaybeUndefVal(block, ptr_src, ptr_or_slice)) == null) |
| | 23786 | ptr_src |
| | 23787 | else if ((try sema.resolveMaybeUndefVal(block, src, start)) == null) |
| | 23788 | start_src |
| | 23789 | else |
| | 23790 | end_src; |
| | 23791 | |
| | 23792 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 23742 | if (block.wantSafety()) { | 23793 | if (block.wantSafety()) { |
| 23743 | // requirement: slicing C ptr is non-null | 23794 | // requirement: slicing C ptr is non-null |
| 23744 | if (ptr_ptr_child_ty.isCPtr()) { | 23795 | if (ptr_ptr_child_ty.isCPtr()) { |
| ... | @@ -23846,7 +23897,7 @@ fn cmpNumeric( | ... | @@ -23846,7 +23897,7 @@ fn cmpNumeric( |
| 23846 | // a full resolution of their value, for example `@sizeOf(@Frame(function))` is known to | 23897 | // a full resolution of their value, for example `@sizeOf(@Frame(function))` is known to |
| 23847 | // always be nonzero, and we benefit from not forcing the full evaluation and stack frame layout | 23898 | // always be nonzero, and we benefit from not forcing the full evaluation and stack frame layout |
| 23848 | // of this function if we don't need to. | 23899 | // of this function if we don't need to. |
| 23849 | try sema.requireRuntimeBlock(block, runtime_src); | 23900 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 23850 | | 23901 | |
| 23851 | // For floats, emit a float comparison instruction. | 23902 | // For floats, emit a float comparison instruction. |
| 23852 | const lhs_is_float = switch (lhs_ty_tag) { | 23903 | const lhs_is_float = switch (lhs_ty_tag) { |
| ... | @@ -24034,7 +24085,7 @@ fn cmpVector( | ... | @@ -24034,7 +24085,7 @@ fn cmpVector( |
| 24034 | } | 24085 | } |
| 24035 | }; | 24086 | }; |
| 24036 | | 24087 | |
| 24037 | try sema.requireRuntimeBlock(block, runtime_src); | 24088 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 24038 | const result_ty_inst = try sema.addType(result_ty); | 24089 | const result_ty_inst = try sema.addType(result_ty); |
| 24039 | return block.addCmpVector(lhs, rhs, op, result_ty_inst); | 24090 | return block.addCmpVector(lhs, rhs, op, result_ty_inst); |
| 24040 | } | 24091 | } |
| ... | @@ -24050,7 +24101,7 @@ fn wrapOptional( | ... | @@ -24050,7 +24101,7 @@ fn wrapOptional( |
| 24050 | return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, val)); | 24101 | return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, val)); |
| 24051 | } | 24102 | } |
| 24052 | | 24103 | |
| 24053 | try sema.requireRuntimeBlock(block, inst_src); | 24104 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 24054 | return block.addTyOp(.wrap_optional, dest_ty, inst); | 24105 | return block.addTyOp(.wrap_optional, dest_ty, inst); |
| 24055 | } | 24106 | } |
| 24056 | | 24107 | |
| ... | @@ -24066,7 +24117,7 @@ fn wrapErrorUnionPayload( | ... | @@ -24066,7 +24117,7 @@ fn wrapErrorUnionPayload( |
| 24066 | if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| { | 24117 | if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| { |
| 24067 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); | 24118 | return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val)); |
| 24068 | } | 24119 | } |
| 24069 | try sema.requireRuntimeBlock(block, inst_src); | 24120 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 24070 | try sema.queueFullTypeResolution(dest_payload_ty); | 24121 | try sema.queueFullTypeResolution(dest_payload_ty); |
| 24071 | return block.addTyOp(.wrap_errunion_payload, dest_ty, coerced); | 24122 | return block.addTyOp(.wrap_errunion_payload, dest_ty, coerced); |
| 24072 | } | 24123 | } |
| ... | @@ -24122,7 +24173,7 @@ fn wrapErrorUnionSet( | ... | @@ -24122,7 +24173,7 @@ fn wrapErrorUnionSet( |
| 24122 | return sema.addConstant(dest_ty, val); | 24173 | return sema.addConstant(dest_ty, val); |
| 24123 | } | 24174 | } |
| 24124 | | 24175 | |
| 24125 | try sema.requireRuntimeBlock(block, inst_src); | 24176 | try sema.requireRuntimeBlock(block, inst_src, null); |
| 24126 | const coerced = try sema.coerce(block, dest_err_set_ty, inst, inst_src); | 24177 | const coerced = try sema.coerce(block, dest_err_set_ty, inst, inst_src); |
| 24127 | return block.addTyOp(.wrap_errunion_err, dest_ty, coerced); | 24178 | return block.addTyOp(.wrap_errunion_err, dest_ty, coerced); |
| 24128 | } | 24179 | } |
| ... | @@ -24140,7 +24191,7 @@ fn unionToTag( | ... | @@ -24140,7 +24191,7 @@ fn unionToTag( |
| 24140 | if (try sema.resolveMaybeUndefVal(block, un_src, un)) |un_val| { | 24191 | if (try sema.resolveMaybeUndefVal(block, un_src, un)) |un_val| { |
| 24141 | return sema.addConstant(enum_ty, un_val.unionTag()); | 24192 | return sema.addConstant(enum_ty, un_val.unionTag()); |
| 24142 | } | 24193 | } |
| 24143 | try sema.requireRuntimeBlock(block, un_src); | 24194 | try sema.requireRuntimeBlock(block, un_src, null); |
| 24144 | return block.addTyOp(.get_union_tag, enum_ty, un); | 24195 | return block.addTyOp(.get_union_tag, enum_ty, un); |
| 24145 | } | 24196 | } |
| 24146 | | 24197 | |
| ... | @@ -25311,7 +25362,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -25311,7 +25362,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 25311 | const field = &struct_obj.fields.values()[i]; | 25362 | const field = &struct_obj.fields.values()[i]; |
| 25312 | const coerced = try sema.coerce(&block_scope, field.ty, init, src); | 25363 | const coerced = try sema.coerce(&block_scope, field.ty, init, src); |
| 25313 | const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, coerced)) orelse | 25364 | const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, coerced)) orelse |
| 25314 | return sema.failWithNeededComptime(&block_scope, src); | 25365 | return sema.failWithNeededComptime(&block_scope, src, "struct field default value must be comptime known"); |
| 25315 | field.default_val = try default_val.copy(decl_arena_allocator); | 25366 | field.default_val = try default_val.copy(decl_arena_allocator); |
| 25316 | } | 25367 | } |
| 25317 | } | 25368 | } |
| ... | @@ -25504,7 +25555,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil | ... | @@ -25504,7 +25555,7 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil |
| 25504 | if (tag_ref != .none) { | 25555 | if (tag_ref != .none) { |
| 25505 | const tag_src = src; // TODO better source location | 25556 | const tag_src = src; // TODO better source location |
| 25506 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); | 25557 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 25507 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced); | 25558 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced, "enum tag value must be comptime known"); |
| 25508 | last_tag_val = val; | 25559 | last_tag_val = val; |
| 25509 | | 25560 | |
| 25510 | // This puts the memory into the union arena, not the enum arena, but | 25561 | // This puts the memory into the union arena, not the enum arena, but |
| ... | @@ -26247,7 +26298,7 @@ pub fn analyzeAddrspace( | ... | @@ -26247,7 +26298,7 @@ pub fn analyzeAddrspace( |
| 26247 | zir_ref: Zir.Inst.Ref, | 26298 | zir_ref: Zir.Inst.Ref, |
| 26248 | ctx: AddressSpaceContext, | 26299 | ctx: AddressSpaceContext, |
| 26249 | ) !std.builtin.AddressSpace { | 26300 | ) !std.builtin.AddressSpace { |
| 26250 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref); | 26301 | const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "addresspace must be comptime known"); |
| 26251 | const address_space = addrspace_tv.val.toEnum(std.builtin.AddressSpace); | 26302 | const address_space = addrspace_tv.val.toEnum(std.builtin.AddressSpace); |
| 26252 | const target = sema.mod.getTarget(); | 26303 | const target = sema.mod.getTarget(); |
| 26253 | const arch = target.cpu.arch; | 26304 | const arch = target.cpu.arch; |