| ... | ... | @@ -880,19 +880,76 @@ fn resolveMaybeUndefValAllowVariables( |
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 883 | | return sema.mod.fail(&block.base, src, "unable to resolve comptime value", .{}); |
| 883 | return sema.fail(block, src, "unable to resolve comptime value", .{}); |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | fn failWithUseOfUndef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 887 | | return sema.mod.fail(&block.base, src, "use of undefined value here causes undefined behavior", .{}); |
| 887 | return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{}); |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | fn failWithDivideByZero(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { |
| 891 | | return sema.mod.fail(&block.base, src, "division by zero here causes undefined behavior", .{}); |
| 891 | return sema.fail(block, src, "division by zero here causes undefined behavior", .{}); |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { |
| 895 | | return sema.mod.fail(&block.base, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); |
| 895 | return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty }); |
| 896 | } |
| 897 | |
| 898 | /// We don't return a pointer to the new error note because the pointer |
| 899 | /// becomes invalid when you add another one. |
| 900 | fn errNote( |
| 901 | sema: *Sema, |
| 902 | block: *Scope.Block, |
| 903 | src: LazySrcLoc, |
| 904 | parent: *Module.ErrorMsg, |
| 905 | comptime format: []const u8, |
| 906 | args: anytype, |
| 907 | ) error{OutOfMemory}!void { |
| 908 | return sema.mod.errNoteNonLazy(src.toSrcLoc(block), parent, format, args); |
| 909 | } |
| 910 | |
| 911 | fn errMsg( |
| 912 | sema: *Sema, |
| 913 | block: *Scope.Block, |
| 914 | src: LazySrcLoc, |
| 915 | comptime format: []const u8, |
| 916 | args: anytype, |
| 917 | ) error{OutOfMemory}!*Module.ErrorMsg { |
| 918 | return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(block), format, args); |
| 919 | } |
| 920 | |
| 921 | pub fn fail( |
| 922 | sema: *Sema, |
| 923 | block: *Scope.Block, |
| 924 | src: LazySrcLoc, |
| 925 | comptime format: []const u8, |
| 926 | args: anytype, |
| 927 | ) CompileError { |
| 928 | const err_msg = try sema.errMsg(block, src, format, args); |
| 929 | return sema.failWithOwnedErrorMsg(err_msg); |
| 930 | } |
| 931 | |
| 932 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 933 | @setCold(true); |
| 934 | |
| 935 | const mod = sema.mod; |
| 936 | |
| 937 | { |
| 938 | errdefer err_msg.destroy(mod.gpa); |
| 939 | if (err_msg.src_loc.lazy == .unneeded) { |
| 940 | return error.NeededSourceLocation; |
| 941 | } |
| 942 | try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1); |
| 943 | try mod.failed_files.ensureUnusedCapacity(mod.gpa, 1); |
| 944 | } |
| 945 | if (sema.owner_func) |func| { |
| 946 | func.state = .sema_failure; |
| 947 | } else { |
| 948 | sema.owner_decl.analysis = .sema_failure; |
| 949 | sema.owner_decl.generation = mod.generation; |
| 950 | } |
| 951 | mod.failed_decls.putAssumeCapacityNoClobber(sema.owner_decl, err_msg); |
| 952 | return error.AnalysisFail; |
| 896 | 953 | } |
| 897 | 954 | |
| 898 | 955 | /// Appropriate to call when the coercion has already been done by result |
| ... | ... | @@ -923,9 +980,9 @@ fn resolveAlign( |
| 923 | 980 | ) !u16 { |
| 924 | 981 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); |
| 925 | 982 | const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line. |
| 926 | | if (alignment == 0) return sema.mod.fail(&block.base, src, "alignment must be >= 1", .{}); |
| 983 | if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{}); |
| 927 | 984 | if (!std.math.isPowerOfTwo(alignment)) { |
| 928 | | return sema.mod.fail(&block.base, src, "alignment value {d} is not a power of two", .{ |
| 985 | return sema.fail(block, src, "alignment value {d} is not a power of two", .{ |
| 929 | 986 | alignment, |
| 930 | 987 | }); |
| 931 | 988 | } |
| ... | ... | @@ -981,7 +1038,7 @@ pub fn resolveInstValue( |
| 981 | 1038 | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 982 | 1039 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 983 | 1040 | const src = inst_data.src(); |
| 984 | | return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{}); |
| 1041 | return sema.fail(block, src, "TODO implement zir_sema.zirBitcastResultPtr", .{}); |
| 985 | 1042 | } |
| 986 | 1043 | |
| 987 | 1044 | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -1177,7 +1234,7 @@ fn zirEnumDecl( |
| 1177 | 1234 | .val = enum_val, |
| 1178 | 1235 | }, type_name); |
| 1179 | 1236 | new_decl.owns_tv = true; |
| 1180 | | errdefer sema.mod.abortAnonDecl(new_decl); |
| 1237 | errdefer mod.abortAnonDecl(new_decl); |
| 1181 | 1238 | |
| 1182 | 1239 | enum_obj.* = .{ |
| 1183 | 1240 | .owner_decl = new_decl, |
| ... | ... | @@ -1292,12 +1349,12 @@ fn zirEnumDecl( |
| 1292 | 1349 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); |
| 1293 | 1350 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); |
| 1294 | 1351 | const msg = msg: { |
| 1295 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate enum tag", .{}); |
| 1352 | const msg = try sema.errMsg(block, field_src, "duplicate enum tag", .{}); |
| 1296 | 1353 | errdefer msg.destroy(gpa); |
| 1297 | | try mod.errNote(&block.base, other_tag_src, msg, "other tag here", .{}); |
| 1354 | try sema.errNote(block, other_tag_src, msg, "other tag here", .{}); |
| 1298 | 1355 | break :msg msg; |
| 1299 | 1356 | }; |
| 1300 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1357 | return sema.failWithOwnedErrorMsg(msg); |
| 1301 | 1358 | } |
| 1302 | 1359 | |
| 1303 | 1360 | if (has_tag_value) { |
| ... | ... | @@ -1400,7 +1457,7 @@ fn zirOpaqueDecl( |
| 1400 | 1457 | |
| 1401 | 1458 | _ = extended; |
| 1402 | 1459 | _ = inst; |
| 1403 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{}); |
| 1460 | return sema.fail(block, sema.src, "TODO implement zirOpaqueDecl", .{}); |
| 1404 | 1461 | } |
| 1405 | 1462 | |
| 1406 | 1463 | fn zirErrorSetDecl( |
| ... | ... | @@ -1509,7 +1566,7 @@ fn ensureResultUsed( |
| 1509 | 1566 | const operand_ty = sema.typeOf(operand); |
| 1510 | 1567 | switch (operand_ty.zigTypeTag()) { |
| 1511 | 1568 | .Void, .NoReturn => return, |
| 1512 | | else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}), |
| 1569 | else => return sema.fail(block, src, "expression value is ignored", .{}), |
| 1513 | 1570 | } |
| 1514 | 1571 | } |
| 1515 | 1572 | |
| ... | ... | @@ -1522,7 +1579,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1522 | 1579 | const src = inst_data.src(); |
| 1523 | 1580 | const operand_ty = sema.typeOf(operand); |
| 1524 | 1581 | switch (operand_ty.zigTypeTag()) { |
| 1525 | | .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}), |
| 1582 | .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded", .{}), |
| 1526 | 1583 | else => return, |
| 1527 | 1584 | } |
| 1528 | 1585 | } |
| ... | ... | @@ -1548,15 +1605,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1548 | 1605 | } |
| 1549 | 1606 | if (!elem_ty.isIndexable()) { |
| 1550 | 1607 | const msg = msg: { |
| 1551 | | const msg = try sema.mod.errMsg( |
| 1552 | | &block.base, |
| 1608 | const msg = try sema.errMsg( |
| 1609 | block, |
| 1553 | 1610 | src, |
| 1554 | 1611 | "type '{}' does not support indexing", |
| 1555 | 1612 | .{elem_ty}, |
| 1556 | 1613 | ); |
| 1557 | 1614 | errdefer msg.destroy(sema.gpa); |
| 1558 | | try sema.mod.errNote( |
| 1559 | | &block.base, |
| 1615 | try sema.errNote( |
| 1616 | block, |
| 1560 | 1617 | src, |
| 1561 | 1618 | msg, |
| 1562 | 1619 | "for loop operand must be an array, slice, tuple, or vector", |
| ... | ... | @@ -1564,13 +1621,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1564 | 1621 | ); |
| 1565 | 1622 | break :msg msg; |
| 1566 | 1623 | }; |
| 1567 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1624 | return sema.failWithOwnedErrorMsg(msg); |
| 1568 | 1625 | } |
| 1569 | 1626 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); |
| 1570 | 1627 | return sema.analyzeLoad(block, src, result_ptr, src); |
| 1571 | 1628 | } |
| 1572 | 1629 | |
| 1573 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirIndexablePtrLen", .{}); |
| 1630 | return sema.fail(block, src, "TODO implement Sema.zirIndexablePtrLen", .{}); |
| 1574 | 1631 | } |
| 1575 | 1632 | |
| 1576 | 1633 | fn zirAllocExtended( |
| ... | ... | @@ -1591,7 +1648,7 @@ fn zirAllocExtended( |
| 1591 | 1648 | extra_index += 1; |
| 1592 | 1649 | break :blk try sema.resolveType(block, ty_src, type_ref); |
| 1593 | 1650 | } else { |
| 1594 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended inferred", .{}); |
| 1651 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended inferred", .{}); |
| 1595 | 1652 | }; |
| 1596 | 1653 | |
| 1597 | 1654 | const alignment: u16 = if (small.has_align) blk: { |
| ... | ... | @@ -1602,11 +1659,11 @@ fn zirAllocExtended( |
| 1602 | 1659 | } else 0; |
| 1603 | 1660 | |
| 1604 | 1661 | if (small.is_comptime) { |
| 1605 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended comptime", .{}); |
| 1662 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended comptime", .{}); |
| 1606 | 1663 | } |
| 1607 | 1664 | |
| 1608 | 1665 | if (!small.is_const) { |
| 1609 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended var", .{}); |
| 1666 | return sema.fail(block, src, "TODO implement Sema.zirAllocExtended var", .{}); |
| 1610 | 1667 | } |
| 1611 | 1668 | |
| 1612 | 1669 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | ... | @@ -1804,12 +1861,10 @@ fn validateUnionInitPtr( |
| 1804 | 1861 | instrs: []const Zir.Inst.Index, |
| 1805 | 1862 | union_ptr: Air.Inst.Ref, |
| 1806 | 1863 | ) CompileError!void { |
| 1807 | | const mod = sema.mod; |
| 1808 | | |
| 1809 | 1864 | if (instrs.len != 1) { |
| 1810 | 1865 | // TODO add note for other field |
| 1811 | 1866 | // TODO add note for union declared here |
| 1812 | | return mod.fail(&block.base, init_src, "only one union field can be active at once", .{}); |
| 1867 | return sema.fail(block, init_src, "only one union field can be active at once", .{}); |
| 1813 | 1868 | } |
| 1814 | 1869 | |
| 1815 | 1870 | const field_ptr = instrs[0]; |
| ... | ... | @@ -1845,7 +1900,6 @@ fn validateStructInitPtr( |
| 1845 | 1900 | instrs: []const Zir.Inst.Index, |
| 1846 | 1901 | ) CompileError!void { |
| 1847 | 1902 | const gpa = sema.gpa; |
| 1848 | | const mod = sema.mod; |
| 1849 | 1903 | |
| 1850 | 1904 | // Maps field index to field_ptr index of where it was already initialized. |
| 1851 | 1905 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); |
| ... | ... | @@ -1864,12 +1918,12 @@ fn validateStructInitPtr( |
| 1864 | 1918 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; |
| 1865 | 1919 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; |
| 1866 | 1920 | const msg = msg: { |
| 1867 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{}); |
| 1921 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 1868 | 1922 | errdefer msg.destroy(gpa); |
| 1869 | | try mod.errNote(&block.base, other_field_src, msg, "other field here", .{}); |
| 1923 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 1870 | 1924 | break :msg msg; |
| 1871 | 1925 | }; |
| 1872 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1926 | return sema.failWithOwnedErrorMsg(msg); |
| 1873 | 1927 | } |
| 1874 | 1928 | found_fields[field_index] = field_ptr; |
| 1875 | 1929 | } |
| ... | ... | @@ -1884,28 +1938,28 @@ fn validateStructInitPtr( |
| 1884 | 1938 | const template = "missing struct field: {s}"; |
| 1885 | 1939 | const args = .{field_name}; |
| 1886 | 1940 | if (root_msg) |msg| { |
| 1887 | | try mod.errNote(&block.base, init_src, msg, template, args); |
| 1941 | try sema.errNote(block, init_src, msg, template, args); |
| 1888 | 1942 | } else { |
| 1889 | | root_msg = try mod.errMsg(&block.base, init_src, template, args); |
| 1943 | root_msg = try sema.errMsg(block, init_src, template, args); |
| 1890 | 1944 | } |
| 1891 | 1945 | } |
| 1892 | 1946 | if (root_msg) |msg| { |
| 1893 | 1947 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1894 | 1948 | defer gpa.free(fqn); |
| 1895 | | try mod.errNoteNonLazy( |
| 1949 | try sema.mod.errNoteNonLazy( |
| 1896 | 1950 | struct_obj.srcLoc(), |
| 1897 | 1951 | msg, |
| 1898 | 1952 | "struct '{s}' declared here", |
| 1899 | 1953 | .{fqn}, |
| 1900 | 1954 | ); |
| 1901 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1955 | return sema.failWithOwnedErrorMsg(msg); |
| 1902 | 1956 | } |
| 1903 | 1957 | } |
| 1904 | 1958 | |
| 1905 | 1959 | fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 1906 | 1960 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1907 | 1961 | const src = inst_data.src(); |
| 1908 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirValidateArrayInitPtr", .{}); |
| 1962 | return sema.fail(block, src, "TODO implement Sema.zirValidateArrayInitPtr", .{}); |
| 1909 | 1963 | } |
| 1910 | 1964 | |
| 1911 | 1965 | fn failWithBadFieldAccess( |
| ... | ... | @@ -1915,24 +1969,23 @@ fn failWithBadFieldAccess( |
| 1915 | 1969 | field_src: LazySrcLoc, |
| 1916 | 1970 | field_name: []const u8, |
| 1917 | 1971 | ) CompileError { |
| 1918 | | const mod = sema.mod; |
| 1919 | 1972 | const gpa = sema.gpa; |
| 1920 | 1973 | |
| 1921 | 1974 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1922 | 1975 | defer gpa.free(fqn); |
| 1923 | 1976 | |
| 1924 | 1977 | const msg = msg: { |
| 1925 | | const msg = try mod.errMsg( |
| 1926 | | &block.base, |
| 1978 | const msg = try sema.errMsg( |
| 1979 | block, |
| 1927 | 1980 | field_src, |
| 1928 | 1981 | "no field named '{s}' in struct '{s}'", |
| 1929 | 1982 | .{ field_name, fqn }, |
| 1930 | 1983 | ); |
| 1931 | 1984 | errdefer msg.destroy(gpa); |
| 1932 | | try mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{}); |
| 1985 | try sema.mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{}); |
| 1933 | 1986 | break :msg msg; |
| 1934 | 1987 | }; |
| 1935 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 1988 | return sema.failWithOwnedErrorMsg(msg); |
| 1936 | 1989 | } |
| 1937 | 1990 | |
| 1938 | 1991 | fn failWithBadUnionFieldAccess( |
| ... | ... | @@ -1942,24 +1995,23 @@ fn failWithBadUnionFieldAccess( |
| 1942 | 1995 | field_src: LazySrcLoc, |
| 1943 | 1996 | field_name: []const u8, |
| 1944 | 1997 | ) CompileError { |
| 1945 | | const mod = sema.mod; |
| 1946 | 1998 | const gpa = sema.gpa; |
| 1947 | 1999 | |
| 1948 | 2000 | const fqn = try union_obj.getFullyQualifiedName(gpa); |
| 1949 | 2001 | defer gpa.free(fqn); |
| 1950 | 2002 | |
| 1951 | 2003 | const msg = msg: { |
| 1952 | | const msg = try mod.errMsg( |
| 1953 | | &block.base, |
| 2004 | const msg = try sema.errMsg( |
| 2005 | block, |
| 1954 | 2006 | field_src, |
| 1955 | 2007 | "no field named '{s}' in union '{s}'", |
| 1956 | 2008 | .{ field_name, fqn }, |
| 1957 | 2009 | ); |
| 1958 | 2010 | errdefer msg.destroy(gpa); |
| 1959 | | try mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{}); |
| 2011 | try sema.mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{}); |
| 1960 | 2012 | break :msg msg; |
| 1961 | 2013 | }; |
| 1962 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2014 | return sema.failWithOwnedErrorMsg(msg); |
| 1963 | 2015 | } |
| 1964 | 2016 | |
| 1965 | 2017 | fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -2150,7 +2202,7 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 2150 | 2202 | const src = inst_data.src(); |
| 2151 | 2203 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2152 | 2204 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand); |
| 2153 | | return sema.mod.fail(&block.base, src, "{s}", .{msg}); |
| 2205 | return sema.fail(block, src, "{s}", .{msg}); |
| 2154 | 2206 | } |
| 2155 | 2207 | |
| 2156 | 2208 | fn zirCompileLog( |
| ... | ... | @@ -2269,7 +2321,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2269 | 2321 | |
| 2270 | 2322 | // we check this here to avoid undefined symbols |
| 2271 | 2323 | if (!@import("build_options").have_llvm) |
| 2272 | | return sema.mod.fail(&parent_block.base, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{}); |
| 2324 | return sema.fail(&parent_block, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{}); |
| 2273 | 2325 | |
| 2274 | 2326 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); |
| 2275 | 2327 | defer c_import_buf.deinit(); |
| ... | ... | @@ -2290,15 +2342,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2290 | 2342 | _ = try sema.analyzeBody(&child_block, body); |
| 2291 | 2343 | |
| 2292 | 2344 | const c_import_res = sema.mod.comp.cImport(c_import_buf.items) catch |err| |
| 2293 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2345 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2294 | 2346 | |
| 2295 | 2347 | if (c_import_res.errors.len != 0) { |
| 2296 | 2348 | const msg = msg: { |
| 2297 | | const msg = try sema.mod.errMsg(&child_block.base, src, "C import failed", .{}); |
| 2349 | const msg = try sema.errMsg(&child_block, src, "C import failed", .{}); |
| 2298 | 2350 | errdefer msg.destroy(sema.gpa); |
| 2299 | 2351 | |
| 2300 | 2352 | if (!sema.mod.comp.bin_file.options.link_libc) |
| 2301 | | try sema.mod.errNote(&child_block.base, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 2353 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 2302 | 2354 | |
| 2303 | 2355 | for (c_import_res.errors) |_| { |
| 2304 | 2356 | // TODO integrate with LazySrcLoc |
| ... | ... | @@ -2310,7 +2362,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2310 | 2362 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); |
| 2311 | 2363 | break :msg msg; |
| 2312 | 2364 | }; |
| 2313 | | return sema.mod.failWithOwnedErrorMsg(&child_block.base, msg); |
| 2365 | return sema.failWithOwnedErrorMsg(msg); |
| 2314 | 2366 | } |
| 2315 | 2367 | const c_import_pkg = Package.create( |
| 2316 | 2368 | sema.gpa, |
| ... | ... | @@ -2326,10 +2378,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2326 | 2378 | try c_import_pkg.add(sema.gpa, "std", std_pkg); |
| 2327 | 2379 | |
| 2328 | 2380 | const result = sema.mod.importPkg(c_import_pkg) catch |err| |
| 2329 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2381 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2330 | 2382 | |
| 2331 | 2383 | sema.mod.astGenFile(result.file) catch |err| |
| 2332 | | return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)}); |
| 2384 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 2333 | 2385 | |
| 2334 | 2386 | try sema.mod.semaFile(result.file); |
| 2335 | 2387 | const file_root_decl = result.file.root_decl.?; |
| ... | ... | @@ -2340,7 +2392,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2340 | 2392 | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2341 | 2393 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2342 | 2394 | const src = inst_data.src(); |
| 2343 | | return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{}); |
| 2395 | return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{}); |
| 2344 | 2396 | } |
| 2345 | 2397 | |
| 2346 | 2398 | fn zirBlock( |
| ... | ... | @@ -2527,11 +2579,11 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 2527 | 2579 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 2528 | 2580 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 2529 | 2581 | if (extra.namespace != .none) { |
| 2530 | | return sema.mod.fail(&block.base, src, "TODO: implement exporting with field access", .{}); |
| 2582 | return sema.fail(block, src, "TODO: implement exporting with field access", .{}); |
| 2531 | 2583 | } |
| 2532 | 2584 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); |
| 2533 | 2585 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2534 | | try sema.mod.analyzeExport(block, src, options, decl); |
| 2586 | try sema.analyzeExport(block, src, options, decl); |
| 2535 | 2587 | } |
| 2536 | 2588 | |
| 2537 | 2589 | fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -2547,40 +2599,117 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2547 | 2599 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2548 | 2600 | const decl = switch (operand.val.tag()) { |
| 2549 | 2601 | .function => operand.val.castTag(.function).?.data.owner_decl, |
| 2550 | | else => return sema.mod.fail(&block.base, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it. |
| 2602 | else => return sema.fail(block, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it. |
| 2551 | 2603 | }; |
| 2552 | | try sema.mod.analyzeExport(block, src, options, decl); |
| 2604 | try sema.analyzeExport(block, src, options, decl); |
| 2553 | 2605 | } |
| 2554 | 2606 | |
| 2555 | | fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2607 | pub fn analyzeExport( |
| 2608 | sema: *Sema, |
| 2609 | block: *Scope.Block, |
| 2610 | src: LazySrcLoc, |
| 2611 | borrowed_options: std.builtin.ExportOptions, |
| 2612 | exported_decl: *Decl, |
| 2613 | ) !void { |
| 2614 | const Export = Module.Export; |
| 2556 | 2615 | const mod = sema.mod; |
| 2616 | |
| 2617 | try mod.ensureDeclAnalyzed(exported_decl); |
| 2618 | switch (exported_decl.ty.zigTypeTag()) { |
| 2619 | .Fn => {}, |
| 2620 | else => return sema.fail(block, src, "unable to export type '{}'", .{exported_decl.ty}), |
| 2621 | } |
| 2622 | |
| 2623 | const gpa = mod.gpa; |
| 2624 | |
| 2625 | try mod.decl_exports.ensureUnusedCapacity(gpa, 1); |
| 2626 | try mod.export_owners.ensureUnusedCapacity(gpa, 1); |
| 2627 | |
| 2628 | const new_export = try gpa.create(Export); |
| 2629 | errdefer gpa.destroy(new_export); |
| 2630 | |
| 2631 | const symbol_name = try gpa.dupe(u8, borrowed_options.name); |
| 2632 | errdefer gpa.free(symbol_name); |
| 2633 | |
| 2634 | const section: ?[]const u8 = if (borrowed_options.section) |s| try gpa.dupe(u8, s) else null; |
| 2635 | errdefer if (section) |s| gpa.free(s); |
| 2636 | |
| 2637 | const src_decl = block.src_decl; |
| 2638 | const owner_decl = sema.owner_decl; |
| 2639 | |
| 2640 | log.debug("exporting Decl '{s}' as symbol '{s}' from Decl '{s}'", .{ |
| 2641 | exported_decl.name, symbol_name, owner_decl.name, |
| 2642 | }); |
| 2643 | |
| 2644 | new_export.* = .{ |
| 2645 | .options = .{ |
| 2646 | .name = symbol_name, |
| 2647 | .linkage = borrowed_options.linkage, |
| 2648 | .section = section, |
| 2649 | }, |
| 2650 | .src = src, |
| 2651 | .link = switch (mod.comp.bin_file.tag) { |
| 2652 | .coff => .{ .coff = {} }, |
| 2653 | .elf => .{ .elf = .{} }, |
| 2654 | .macho => .{ .macho = .{} }, |
| 2655 | .plan9 => .{ .plan9 = null }, |
| 2656 | .c => .{ .c = {} }, |
| 2657 | .wasm => .{ .wasm = {} }, |
| 2658 | .spirv => .{ .spirv = {} }, |
| 2659 | }, |
| 2660 | .owner_decl = owner_decl, |
| 2661 | .src_decl = src_decl, |
| 2662 | .exported_decl = exported_decl, |
| 2663 | .status = .in_progress, |
| 2664 | }; |
| 2665 | |
| 2666 | // Add to export_owners table. |
| 2667 | const eo_gop = mod.export_owners.getOrPutAssumeCapacity(owner_decl); |
| 2668 | if (!eo_gop.found_existing) { |
| 2669 | eo_gop.value_ptr.* = &[0]*Export{}; |
| 2670 | } |
| 2671 | eo_gop.value_ptr.* = try gpa.realloc(eo_gop.value_ptr.*, eo_gop.value_ptr.len + 1); |
| 2672 | eo_gop.value_ptr.*[eo_gop.value_ptr.len - 1] = new_export; |
| 2673 | errdefer eo_gop.value_ptr.* = gpa.shrink(eo_gop.value_ptr.*, eo_gop.value_ptr.len - 1); |
| 2674 | |
| 2675 | // Add to exported_decl table. |
| 2676 | const de_gop = mod.decl_exports.getOrPutAssumeCapacity(exported_decl); |
| 2677 | if (!de_gop.found_existing) { |
| 2678 | de_gop.value_ptr.* = &[0]*Export{}; |
| 2679 | } |
| 2680 | de_gop.value_ptr.* = try gpa.realloc(de_gop.value_ptr.*, de_gop.value_ptr.len + 1); |
| 2681 | de_gop.value_ptr.*[de_gop.value_ptr.len - 1] = new_export; |
| 2682 | errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1); |
| 2683 | } |
| 2684 | |
| 2685 | fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2557 | 2686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2558 | 2687 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2559 | 2688 | const src: LazySrcLoc = inst_data.src(); |
| 2560 | 2689 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); |
| 2561 | 2690 | if (alignment > 256) { |
| 2562 | | return mod.fail(&block.base, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| 2691 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| 2563 | 2692 | alignment, |
| 2564 | 2693 | }); |
| 2565 | 2694 | } |
| 2566 | 2695 | const func = sema.owner_func orelse |
| 2567 | | return mod.fail(&block.base, src, "@setAlignStack outside function body", .{}); |
| 2696 | return sema.fail(block, src, "@setAlignStack outside function body", .{}); |
| 2568 | 2697 | |
| 2569 | 2698 | switch (func.owner_decl.ty.fnCallingConvention()) { |
| 2570 | | .Naked => return mod.fail(&block.base, src, "@setAlignStack in naked function", .{}), |
| 2571 | | .Inline => return mod.fail(&block.base, src, "@setAlignStack in inline function", .{}), |
| 2699 | .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), |
| 2700 | .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), |
| 2572 | 2701 | else => {}, |
| 2573 | 2702 | } |
| 2574 | 2703 | |
| 2575 | | const gop = try mod.align_stack_fns.getOrPut(mod.gpa, func); |
| 2704 | const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func); |
| 2576 | 2705 | if (gop.found_existing) { |
| 2577 | 2706 | const msg = msg: { |
| 2578 | | const msg = try mod.errMsg(&block.base, src, "multiple @setAlignStack in the same function body", .{}); |
| 2579 | | errdefer msg.destroy(mod.gpa); |
| 2580 | | try mod.errNote(&block.base, src, msg, "other instance here", .{}); |
| 2707 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); |
| 2708 | errdefer msg.destroy(sema.gpa); |
| 2709 | try sema.errNote(block, src, msg, "other instance here", .{}); |
| 2581 | 2710 | break :msg msg; |
| 2582 | 2711 | }; |
| 2583 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2712 | return sema.failWithOwnedErrorMsg(msg); |
| 2584 | 2713 | } |
| 2585 | 2714 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; |
| 2586 | 2715 | } |
| ... | ... | @@ -2596,7 +2725,7 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2596 | 2725 | fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2597 | 2726 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2598 | 2727 | const src: LazySrcLoc = inst_data.src(); |
| 2599 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetFloatMode", .{}); |
| 2728 | return sema.fail(block, src, "TODO: implement Sema.zirSetFloatMode", .{}); |
| 2600 | 2729 | } |
| 2601 | 2730 | |
| 2602 | 2731 | fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -2613,7 +2742,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2613 | 2742 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); |
| 2614 | 2743 | |
| 2615 | 2744 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { |
| 2616 | | return sema.mod.fail(&block.base, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| 2745 | return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{}); |
| 2617 | 2746 | } |
| 2618 | 2747 | |
| 2619 | 2748 | _ = try block.addInst(.{ |
| ... | ... | @@ -2757,7 +2886,7 @@ fn lookupInNamespace( |
| 2757 | 2886 | }, |
| 2758 | 2887 | else => { |
| 2759 | 2888 | const msg = msg: { |
| 2760 | | const msg = try mod.errMsg(&block.base, src, "ambiguous reference", .{}); |
| 2889 | const msg = try sema.errMsg(block, src, "ambiguous reference", .{}); |
| 2761 | 2890 | errdefer msg.destroy(gpa); |
| 2762 | 2891 | for (candidates.items) |candidate| { |
| 2763 | 2892 | const src_loc = candidate.srcLoc(); |
| ... | ... | @@ -2765,7 +2894,7 @@ fn lookupInNamespace( |
| 2765 | 2894 | } |
| 2766 | 2895 | break :msg msg; |
| 2767 | 2896 | }; |
| 2768 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 2897 | return sema.failWithOwnedErrorMsg(msg); |
| 2769 | 2898 | }, |
| 2770 | 2899 | } |
| 2771 | 2900 | } else if (namespace.decls.get(ident_name)) |decl| { |
| ... | ... | @@ -2899,14 +3028,14 @@ fn analyzeCall( |
| 2899 | 3028 | |
| 2900 | 3029 | const func_ty = sema.typeOf(func); |
| 2901 | 3030 | if (func_ty.zigTypeTag() != .Fn) |
| 2902 | | return mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty}); |
| 3031 | return sema.fail(block, func_src, "type '{}' not a function", .{func_ty}); |
| 2903 | 3032 | |
| 2904 | 3033 | const func_ty_info = func_ty.fnInfo(); |
| 2905 | 3034 | const cc = func_ty_info.cc; |
| 2906 | 3035 | if (cc == .Naked) { |
| 2907 | 3036 | // TODO add error note: declared here |
| 2908 | | return mod.fail( |
| 2909 | | &block.base, |
| 3037 | return sema.fail( |
| 3038 | block, |
| 2910 | 3039 | func_src, |
| 2911 | 3040 | "unable to call function with naked calling convention", |
| 2912 | 3041 | .{}, |
| ... | ... | @@ -2917,8 +3046,8 @@ fn analyzeCall( |
| 2917 | 3046 | assert(cc == .C); |
| 2918 | 3047 | if (uncasted_args.len < fn_params_len) { |
| 2919 | 3048 | // TODO add error note: declared here |
| 2920 | | return mod.fail( |
| 2921 | | &block.base, |
| 3049 | return sema.fail( |
| 3050 | block, |
| 2922 | 3051 | func_src, |
| 2923 | 3052 | "expected at least {d} argument(s), found {d}", |
| 2924 | 3053 | .{ fn_params_len, uncasted_args.len }, |
| ... | ... | @@ -2926,8 +3055,8 @@ fn analyzeCall( |
| 2926 | 3055 | } |
| 2927 | 3056 | } else if (fn_params_len != uncasted_args.len) { |
| 2928 | 3057 | // TODO add error note: declared here |
| 2929 | | return mod.fail( |
| 2930 | | &block.base, |
| 3058 | return sema.fail( |
| 3059 | block, |
| 2931 | 3060 | func_src, |
| 2932 | 3061 | "expected {d} argument(s), found {d}", |
| 2933 | 3062 | .{ fn_params_len, uncasted_args.len }, |
| ... | ... | @@ -2945,7 +3074,7 @@ fn analyzeCall( |
| 2945 | 3074 | .never_inline, |
| 2946 | 3075 | .no_async, |
| 2947 | 3076 | .always_tail, |
| 2948 | | => return mod.fail(&block.base, call_src, "TODO implement call with modifier {}", .{ |
| 3077 | => return sema.fail(block, call_src, "TODO implement call with modifier {}", .{ |
| 2949 | 3078 | modifier, |
| 2950 | 3079 | }), |
| 2951 | 3080 | } |
| ... | ... | @@ -2960,7 +3089,7 @@ fn analyzeCall( |
| 2960 | 3089 | const func_val = try sema.resolveConstValue(block, func_src, func); |
| 2961 | 3090 | const module_fn = switch (func_val.tag()) { |
| 2962 | 3091 | .function => func_val.castTag(.function).?.data, |
| 2963 | | .extern_fn => return mod.fail(&block.base, call_src, "{s} call of extern function", .{ |
| 3092 | .extern_fn => return sema.fail(block, call_src, "{s} call of extern function", .{ |
| 2964 | 3093 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 2965 | 3094 | }), |
| 2966 | 3095 | else => unreachable, |
| ... | ... | @@ -3633,7 +3762,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3633 | 3762 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 3634 | 3763 | |
| 3635 | 3764 | if (error_union.zigTypeTag() != .ErrorSet) { |
| 3636 | | return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{ |
| 3765 | return sema.fail(block, lhs_src, "expected error set type, found {}", .{ |
| 3637 | 3766 | error_union.elemType(), |
| 3638 | 3767 | }); |
| 3639 | 3768 | } |
| ... | ... | @@ -3699,7 +3828,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3699 | 3828 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { |
| 3700 | 3829 | const int = value.toUnsignedInt(); |
| 3701 | 3830 | if (int > sema.mod.global_error_set.count() or int == 0) |
| 3702 | | return sema.mod.fail(&block.base, operand_src, "integer value {d} represents no error", .{int}); |
| 3831 | return sema.fail(block, operand_src, "integer value {d} represents no error", .{int}); |
| 3703 | 3832 | const payload = try sema.arena.create(Value.Payload.Error); |
| 3704 | 3833 | payload.* = .{ |
| 3705 | 3834 | .base = .{ .tag = .@"error" }, |
| ... | ... | @@ -3709,7 +3838,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3709 | 3838 | } |
| 3710 | 3839 | try sema.requireRuntimeBlock(block, src); |
| 3711 | 3840 | if (block.wantSafety()) { |
| 3712 | | return sema.mod.fail(&block.base, src, "TODO: get max errors in compilation", .{}); |
| 3841 | return sema.fail(block, src, "TODO: get max errors in compilation", .{}); |
| 3713 | 3842 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 3714 | 3843 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); |
| 3715 | 3844 | } |
| ... | ... | @@ -3729,19 +3858,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3729 | 3858 | const rhs = sema.resolveInst(extra.rhs); |
| 3730 | 3859 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { |
| 3731 | 3860 | const msg = msg: { |
| 3732 | | const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{}); |
| 3861 | const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{}); |
| 3733 | 3862 | errdefer msg.destroy(sema.gpa); |
| 3734 | | try sema.mod.errNote(&block.base, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 3863 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 3735 | 3864 | break :msg msg; |
| 3736 | 3865 | }; |
| 3737 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 3866 | return sema.failWithOwnedErrorMsg(msg); |
| 3738 | 3867 | } |
| 3739 | 3868 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 3740 | 3869 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| 3741 | 3870 | if (lhs_ty.zigTypeTag() != .ErrorSet) |
| 3742 | | return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{lhs_ty}); |
| 3871 | return sema.fail(block, lhs_src, "expected error set type, found {}", .{lhs_ty}); |
| 3743 | 3872 | if (rhs_ty.zigTypeTag() != .ErrorSet) |
| 3744 | | return sema.mod.fail(&block.base, rhs_src, "expected error set type, found {}", .{rhs_ty}); |
| 3873 | return sema.fail(block, rhs_src, "expected error set type, found {}", .{rhs_ty}); |
| 3745 | 3874 | |
| 3746 | 3875 | // Anything merged with anyerror is anyerror. |
| 3747 | 3876 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { |
| ... | ... | @@ -3814,7 +3943,6 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 3814 | 3943 | } |
| 3815 | 3944 | |
| 3816 | 3945 | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3817 | | const mod = sema.mod; |
| 3818 | 3946 | const arena = sema.arena; |
| 3819 | 3947 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3820 | 3948 | const src = inst_data.src(); |
| ... | ... | @@ -3826,17 +3954,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3826 | 3954 | .Enum => operand, |
| 3827 | 3955 | .Union => { |
| 3828 | 3956 | //if (!operand_ty.unionHasTag()) { |
| 3829 | | // return mod.fail( |
| 3830 | | // &block.base, |
| 3957 | // return sema.fail( |
| 3958 | // block, |
| 3831 | 3959 | // operand_src, |
| 3832 | 3960 | // "untagged union '{}' cannot be converted to integer", |
| 3833 | 3961 | // .{dest_ty_src}, |
| 3834 | 3962 | // ); |
| 3835 | 3963 | //} |
| 3836 | | return mod.fail(&block.base, operand_src, "TODO zirEnumToInt for tagged unions", .{}); |
| 3964 | return sema.fail(block, operand_src, "TODO zirEnumToInt for tagged unions", .{}); |
| 3837 | 3965 | }, |
| 3838 | 3966 | else => { |
| 3839 | | return mod.fail(&block.base, operand_src, "expected enum or tagged union, found {}", .{ |
| 3967 | return sema.fail(block, operand_src, "expected enum or tagged union, found {}", .{ |
| 3840 | 3968 | operand_ty, |
| 3841 | 3969 | }); |
| 3842 | 3970 | }, |
| ... | ... | @@ -3861,8 +3989,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3861 | 3989 | } |
| 3862 | 3990 | |
| 3863 | 3991 | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3864 | | const mod = sema.mod; |
| 3865 | | const target = mod.getTarget(); |
| 3992 | const target = sema.mod.getTarget(); |
| 3866 | 3993 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3867 | 3994 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3868 | 3995 | const src = inst_data.src(); |
| ... | ... | @@ -3872,7 +3999,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3872 | 3999 | const operand = sema.resolveInst(extra.rhs); |
| 3873 | 4000 | |
| 3874 | 4001 | if (dest_ty.zigTypeTag() != .Enum) { |
| 3875 | | return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty}); |
| 4002 | return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty}); |
| 3876 | 4003 | } |
| 3877 | 4004 | |
| 3878 | 4005 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { |
| ... | ... | @@ -3884,14 +4011,14 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3884 | 4011 | } |
| 3885 | 4012 | if (!dest_ty.enumHasInt(int_val, target)) { |
| 3886 | 4013 | const msg = msg: { |
| 3887 | | const msg = try mod.errMsg( |
| 3888 | | &block.base, |
| 4014 | const msg = try sema.errMsg( |
| 4015 | block, |
| 3889 | 4016 | src, |
| 3890 | 4017 | "enum '{}' has no tag with value {}", |
| 3891 | 4018 | .{ dest_ty, int_val }, |
| 3892 | 4019 | ); |
| 3893 | 4020 | errdefer msg.destroy(sema.gpa); |
| 3894 | | try mod.errNoteNonLazy( |
| 4021 | try sema.mod.errNoteNonLazy( |
| 3895 | 4022 | dest_ty.declSrcLoc(), |
| 3896 | 4023 | msg, |
| 3897 | 4024 | "enum declared here", |
| ... | ... | @@ -3899,7 +4026,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3899 | 4026 | ); |
| 3900 | 4027 | break :msg msg; |
| 3901 | 4028 | }; |
| 3902 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 4029 | return sema.failWithOwnedErrorMsg(msg); |
| 3903 | 4030 | } |
| 3904 | 4031 | return sema.addConstant(dest_ty, int_val); |
| 3905 | 4032 | } |
| ... | ... | @@ -3926,7 +4053,7 @@ fn zirOptionalPayloadPtr( |
| 3926 | 4053 | |
| 3927 | 4054 | const opt_type = optional_ptr_ty.elemType(); |
| 3928 | 4055 | if (opt_type.zigTypeTag() != .Optional) { |
| 3929 | | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 4056 | return sema.fail(block, src, "expected optional type, found {}", .{opt_type}); |
| 3930 | 4057 | } |
| 3931 | 4058 | |
| 3932 | 4059 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| ... | ... | @@ -3939,7 +4066,7 @@ fn zirOptionalPayloadPtr( |
| 3939 | 4066 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { |
| 3940 | 4067 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 3941 | 4068 | if (val.isNull()) { |
| 3942 | | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 4069 | return sema.fail(block, src, "unable to unwrap null", .{}); |
| 3943 | 4070 | } |
| 3944 | 4071 | // The same Value represents the pointer to the optional and the payload. |
| 3945 | 4072 | return sema.addConstant( |
| ... | ... | @@ -3973,14 +4100,14 @@ fn zirOptionalPayload( |
| 3973 | 4100 | const operand_ty = sema.typeOf(operand); |
| 3974 | 4101 | const opt_type = operand_ty; |
| 3975 | 4102 | if (opt_type.zigTypeTag() != .Optional) { |
| 3976 | | return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type}); |
| 4103 | return sema.fail(block, src, "expected optional type, found {}", .{opt_type}); |
| 3977 | 4104 | } |
| 3978 | 4105 | |
| 3979 | 4106 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 3980 | 4107 | |
| 3981 | 4108 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 3982 | 4109 | if (val.isNull()) { |
| 3983 | | return sema.mod.fail(&block.base, src, "unable to unwrap null", .{}); |
| 4110 | return sema.fail(block, src, "unable to unwrap null", .{}); |
| 3984 | 4111 | } |
| 3985 | 4112 | const sub_val = val.castTag(.opt_payload).?.data; |
| 3986 | 4113 | return sema.addConstant(child_type, sub_val); |
| ... | ... | @@ -4010,11 +4137,11 @@ fn zirErrUnionPayload( |
| 4010 | 4137 | const operand_src = src; |
| 4011 | 4138 | const operand_ty = sema.typeOf(operand); |
| 4012 | 4139 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4013 | | return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty}); |
| 4140 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{operand_ty}); |
| 4014 | 4141 | |
| 4015 | 4142 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4016 | 4143 | if (val.getError()) |name| { |
| 4017 | | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 4144 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); |
| 4018 | 4145 | } |
| 4019 | 4146 | const data = val.castTag(.eu_payload).?.data; |
| 4020 | 4147 | const result_ty = operand_ty.errorUnionPayload(); |
| ... | ... | @@ -4046,7 +4173,7 @@ fn zirErrUnionPayloadPtr( |
| 4046 | 4173 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4047 | 4174 | |
| 4048 | 4175 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| 4049 | | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4176 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4050 | 4177 | |
| 4051 | 4178 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 4052 | 4179 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ |
| ... | ... | @@ -4058,7 +4185,7 @@ fn zirErrUnionPayloadPtr( |
| 4058 | 4185 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 4059 | 4186 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 4060 | 4187 | if (val.getError()) |name| { |
| 4061 | | return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name}); |
| 4188 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); |
| 4062 | 4189 | } |
| 4063 | 4190 | return sema.addConstant( |
| 4064 | 4191 | operand_pointer_ty, |
| ... | ... | @@ -4085,7 +4212,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4085 | 4212 | const operand = sema.resolveInst(inst_data.operand); |
| 4086 | 4213 | const operand_ty = sema.typeOf(operand); |
| 4087 | 4214 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4088 | | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4215 | return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4089 | 4216 | |
| 4090 | 4217 | const result_ty = operand_ty.errorUnionSet(); |
| 4091 | 4218 | |
| ... | ... | @@ -4110,7 +4237,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4110 | 4237 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4111 | 4238 | |
| 4112 | 4239 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) |
| 4113 | | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4240 | return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 4114 | 4241 | |
| 4115 | 4242 | const result_ty = operand_ty.elemType().errorUnionSet(); |
| 4116 | 4243 | |
| ... | ... | @@ -4134,9 +4261,9 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 4134 | 4261 | const operand = sema.resolveInst(inst_data.operand); |
| 4135 | 4262 | const operand_ty = sema.typeOf(operand); |
| 4136 | 4263 | if (operand_ty.zigTypeTag() != .ErrorUnion) |
| 4137 | | return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4264 | return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty}); |
| 4138 | 4265 | if (operand_ty.errorUnionPayload().zigTypeTag() != .Void) { |
| 4139 | | return sema.mod.fail(&block.base, src, "expression value is ignored", .{}); |
| 4266 | return sema.fail(block, src, "expression value is ignored", .{}); |
| 4140 | 4267 | } |
| 4141 | 4268 | } |
| 4142 | 4269 | |
| ... | ... | @@ -4277,7 +4404,7 @@ fn funcCommon( |
| 4277 | 4404 | } |
| 4278 | 4405 | |
| 4279 | 4406 | if (align_val.tag() != .null_value) { |
| 4280 | | return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{}); |
| 4407 | return sema.fail(block, src, "TODO implement support for function prototypes to have alignment specified", .{}); |
| 4281 | 4408 | } |
| 4282 | 4409 | |
| 4283 | 4410 | is_generic = is_generic or bare_return_type.requiresComptime(); |
| ... | ... | @@ -4309,15 +4436,15 @@ fn funcCommon( |
| 4309 | 4436 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; |
| 4310 | 4437 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); |
| 4311 | 4438 | mod.comp.stage1AddLinkLib(lib_name) catch |err| { |
| 4312 | | return mod.fail(&block.base, lib_name_src, "unable to add link lib '{s}': {s}", .{ |
| 4439 | return sema.fail(block, lib_name_src, "unable to add link lib '{s}': {s}", .{ |
| 4313 | 4440 | lib_name, @errorName(err), |
| 4314 | 4441 | }); |
| 4315 | 4442 | }; |
| 4316 | 4443 | const target = mod.getTarget(); |
| 4317 | 4444 | if (target_util.is_libc_lib_name(target, lib_name)) { |
| 4318 | 4445 | if (!mod.comp.bin_file.options.link_libc) { |
| 4319 | | return mod.fail( |
| 4320 | | &block.base, |
| 4446 | return sema.fail( |
| 4447 | block, |
| 4321 | 4448 | lib_name_src, |
| 4322 | 4449 | "dependency on libc must be explicitly specified in the build command", |
| 4323 | 4450 | .{}, |
| ... | ... | @@ -4327,8 +4454,8 @@ fn funcCommon( |
| 4327 | 4454 | } |
| 4328 | 4455 | if (target_util.is_libcpp_lib_name(target, lib_name)) { |
| 4329 | 4456 | if (!mod.comp.bin_file.options.link_libcpp) { |
| 4330 | | return mod.fail( |
| 4331 | | &block.base, |
| 4457 | return sema.fail( |
| 4458 | block, |
| 4332 | 4459 | lib_name_src, |
| 4333 | 4460 | "dependency on libc++ must be explicitly specified in the build command", |
| 4334 | 4461 | .{}, |
| ... | ... | @@ -4337,8 +4464,8 @@ fn funcCommon( |
| 4337 | 4464 | break :blk; |
| 4338 | 4465 | } |
| 4339 | 4466 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { |
| 4340 | | return mod.fail( |
| 4341 | | &block.base, |
| 4467 | return sema.fail( |
| 4468 | block, |
| 4342 | 4469 | lib_name_src, |
| 4343 | 4470 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", |
| 4344 | 4471 | .{ lib_name, lib_name }, |
| ... | ... | @@ -4528,7 +4655,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4528 | 4655 | const ptr_ty = sema.typeOf(ptr); |
| 4529 | 4656 | if (ptr_ty.zigTypeTag() != .Pointer) { |
| 4530 | 4657 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 4531 | | return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}); |
| 4658 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty}); |
| 4532 | 4659 | } |
| 4533 | 4660 | // TODO handle known-pointer-address |
| 4534 | 4661 | const src = inst_data.src(); |
| ... | ... | @@ -4639,7 +4766,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4639 | 4766 | if (try sema.isComptimeKnown(block, operand_src, operand)) { |
| 4640 | 4767 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4641 | 4768 | } else if (dest_is_comptime_int) { |
| 4642 | | return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_int'", .{}); |
| 4769 | return sema.fail(block, src, "unable to cast runtime value to 'comptime_int'", .{}); |
| 4643 | 4770 | } |
| 4644 | 4771 | |
| 4645 | 4772 | try sema.requireRuntimeBlock(block, operand_src); |
| ... | ... | @@ -4676,8 +4803,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4676 | 4803 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { |
| 4677 | 4804 | .ComptimeFloat => true, |
| 4678 | 4805 | .Float => false, |
| 4679 | | else => return sema.mod.fail( |
| 4680 | | &block.base, |
| 4806 | else => return sema.fail( |
| 4807 | block, |
| 4681 | 4808 | dest_ty_src, |
| 4682 | 4809 | "expected float type, found '{}'", |
| 4683 | 4810 | .{dest_type}, |
| ... | ... | @@ -4687,8 +4814,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4687 | 4814 | const operand_ty = sema.typeOf(operand); |
| 4688 | 4815 | switch (operand_ty.zigTypeTag()) { |
| 4689 | 4816 | .ComptimeFloat, .Float, .ComptimeInt => {}, |
| 4690 | | else => return sema.mod.fail( |
| 4691 | | &block.base, |
| 4817 | else => return sema.fail( |
| 4818 | block, |
| 4692 | 4819 | operand_src, |
| 4693 | 4820 | "expected float type, found '{}'", |
| 4694 | 4821 | .{operand_ty}, |
| ... | ... | @@ -4699,7 +4826,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4699 | 4826 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4700 | 4827 | } |
| 4701 | 4828 | if (dest_is_comptime_float) { |
| 4702 | | return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_float'", .{}); |
| 4829 | return sema.fail(block, src, "unable to cast runtime value to 'comptime_float'", .{}); |
| 4703 | 4830 | } |
| 4704 | 4831 | const target = sema.mod.getTarget(); |
| 4705 | 4832 | const src_bits = operand_ty.floatBits(target); |
| ... | ... | @@ -4817,7 +4944,7 @@ fn zirSwitchCapture( |
| 4817 | 4944 | |
| 4818 | 4945 | _ = is_ref; |
| 4819 | 4946 | _ = is_multi; |
| 4820 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{}); |
| 4947 | return sema.fail(block, src, "TODO implement Sema for zirSwitchCapture", .{}); |
| 4821 | 4948 | } |
| 4822 | 4949 | |
| 4823 | 4950 | fn zirSwitchCaptureElse( |
| ... | ... | @@ -4835,7 +4962,7 @@ fn zirSwitchCaptureElse( |
| 4835 | 4962 | const src = switch_info.src(); |
| 4836 | 4963 | |
| 4837 | 4964 | _ = is_ref; |
| 4838 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{}); |
| 4965 | return sema.fail(block, src, "TODO implement Sema for zirSwitchCaptureElse", .{}); |
| 4839 | 4966 | } |
| 4840 | 4967 | |
| 4841 | 4968 | fn zirSwitchBlock( |
| ... | ... | @@ -4916,7 +5043,6 @@ fn analyzeSwitch( |
| 4916 | 5043 | src_node_offset: i32, |
| 4917 | 5044 | ) CompileError!Air.Inst.Ref { |
| 4918 | 5045 | const gpa = sema.gpa; |
| 4919 | | const mod = sema.mod; |
| 4920 | 5046 | |
| 4921 | 5047 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { |
| 4922 | 5048 | .none => .{ .body = &.{}, .end = extra_end }, |
| ... | ... | @@ -4938,15 +5064,15 @@ fn analyzeSwitch( |
| 4938 | 5064 | // Validate usage of '_' prongs. |
| 4939 | 5065 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { |
| 4940 | 5066 | const msg = msg: { |
| 4941 | | const msg = try mod.errMsg( |
| 4942 | | &block.base, |
| 5067 | const msg = try sema.errMsg( |
| 5068 | block, |
| 4943 | 5069 | src, |
| 4944 | 5070 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 4945 | 5071 | .{}, |
| 4946 | 5072 | ); |
| 4947 | 5073 | errdefer msg.destroy(gpa); |
| 4948 | | try mod.errNote( |
| 4949 | | &block.base, |
| 5074 | try sema.errNote( |
| 5075 | block, |
| 4950 | 5076 | special_prong_src, |
| 4951 | 5077 | msg, |
| 4952 | 5078 | "'_' prong here", |
| ... | ... | @@ -4954,7 +5080,7 @@ fn analyzeSwitch( |
| 4954 | 5080 | ); |
| 4955 | 5081 | break :msg msg; |
| 4956 | 5082 | }; |
| 4957 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5083 | return sema.failWithOwnedErrorMsg(msg); |
| 4958 | 5084 | } |
| 4959 | 5085 | |
| 4960 | 5086 | // Validate for duplicate items, missing else prong, and invalid range. |
| ... | ... | @@ -5017,8 +5143,8 @@ fn analyzeSwitch( |
| 5017 | 5143 | .none => { |
| 5018 | 5144 | if (!all_tags_handled) { |
| 5019 | 5145 | const msg = msg: { |
| 5020 | | const msg = try mod.errMsg( |
| 5021 | | &block.base, |
| 5146 | const msg = try sema.errMsg( |
| 5147 | block, |
| 5022 | 5148 | src, |
| 5023 | 5149 | "switch must handle all possibilities", |
| 5024 | 5150 | .{}, |
| ... | ... | @@ -5030,15 +5156,15 @@ fn analyzeSwitch( |
| 5030 | 5156 | const field_name = operand_ty.enumFieldName(i); |
| 5031 | 5157 | |
| 5032 | 5158 | // TODO have this point to the tag decl instead of here |
| 5033 | | try mod.errNote( |
| 5034 | | &block.base, |
| 5159 | try sema.errNote( |
| 5160 | block, |
| 5035 | 5161 | src, |
| 5036 | 5162 | msg, |
| 5037 | 5163 | "unhandled enumeration value: '{s}'", |
| 5038 | 5164 | .{field_name}, |
| 5039 | 5165 | ); |
| 5040 | 5166 | } |
| 5041 | | try mod.errNoteNonLazy( |
| 5167 | try sema.mod.errNoteNonLazy( |
| 5042 | 5168 | operand_ty.declSrcLoc(), |
| 5043 | 5169 | msg, |
| 5044 | 5170 | "enum '{}' declared here", |
| ... | ... | @@ -5046,20 +5172,20 @@ fn analyzeSwitch( |
| 5046 | 5172 | ); |
| 5047 | 5173 | break :msg msg; |
| 5048 | 5174 | }; |
| 5049 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5175 | return sema.failWithOwnedErrorMsg(msg); |
| 5050 | 5176 | } |
| 5051 | 5177 | }, |
| 5052 | 5178 | .under => { |
| 5053 | | if (all_tags_handled) return mod.fail( |
| 5054 | | &block.base, |
| 5179 | if (all_tags_handled) return sema.fail( |
| 5180 | block, |
| 5055 | 5181 | special_prong_src, |
| 5056 | 5182 | "unreachable '_' prong; all cases already handled", |
| 5057 | 5183 | .{}, |
| 5058 | 5184 | ); |
| 5059 | 5185 | }, |
| 5060 | 5186 | .@"else" => { |
| 5061 | | if (all_tags_handled) return mod.fail( |
| 5062 | | &block.base, |
| 5187 | if (all_tags_handled) return sema.fail( |
| 5188 | block, |
| 5063 | 5189 | special_prong_src, |
| 5064 | 5190 | "unreachable else prong; all cases already handled", |
| 5065 | 5191 | .{}, |
| ... | ... | @@ -5068,8 +5194,8 @@ fn analyzeSwitch( |
| 5068 | 5194 | } |
| 5069 | 5195 | }, |
| 5070 | 5196 | |
| 5071 | | .ErrorSet => return mod.fail(&block.base, src, "TODO validate switch .ErrorSet", .{}), |
| 5072 | | .Union => return mod.fail(&block.base, src, "TODO validate switch .Union", .{}), |
| 5197 | .ErrorSet => return sema.fail(block, src, "TODO validate switch .ErrorSet", .{}), |
| 5198 | .Union => return sema.fail(block, src, "TODO validate switch .Union", .{}), |
| 5073 | 5199 | .Int, .ComptimeInt => { |
| 5074 | 5200 | var range_set = RangeSet.init(gpa); |
| 5075 | 5201 | defer range_set.deinit(); |
| ... | ... | @@ -5144,12 +5270,13 @@ fn analyzeSwitch( |
| 5144 | 5270 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 5145 | 5271 | defer arena.deinit(); |
| 5146 | 5272 | |
| 5147 | | const min_int = try operand_ty.minInt(&arena.allocator, mod.getTarget()); |
| 5148 | | const max_int = try operand_ty.maxInt(&arena.allocator, mod.getTarget()); |
| 5273 | const target = sema.mod.getTarget(); |
| 5274 | const min_int = try operand_ty.minInt(&arena.allocator, target); |
| 5275 | const max_int = try operand_ty.maxInt(&arena.allocator, target); |
| 5149 | 5276 | if (try range_set.spans(min_int, max_int, operand_ty)) { |
| 5150 | 5277 | if (special_prong == .@"else") { |
| 5151 | | return mod.fail( |
| 5152 | | &block.base, |
| 5278 | return sema.fail( |
| 5279 | block, |
| 5153 | 5280 | special_prong_src, |
| 5154 | 5281 | "unreachable else prong; all cases already handled", |
| 5155 | 5282 | .{}, |
| ... | ... | @@ -5159,8 +5286,8 @@ fn analyzeSwitch( |
| 5159 | 5286 | } |
| 5160 | 5287 | } |
| 5161 | 5288 | if (special_prong != .@"else") { |
| 5162 | | return mod.fail( |
| 5163 | | &block.base, |
| 5289 | return sema.fail( |
| 5290 | block, |
| 5164 | 5291 | src, |
| 5165 | 5292 | "switch must handle all possibilities", |
| 5166 | 5293 | .{}, |
| ... | ... | @@ -5221,8 +5348,8 @@ fn analyzeSwitch( |
| 5221 | 5348 | switch (special_prong) { |
| 5222 | 5349 | .@"else" => { |
| 5223 | 5350 | if (true_count + false_count == 2) { |
| 5224 | | return mod.fail( |
| 5225 | | &block.base, |
| 5351 | return sema.fail( |
| 5352 | block, |
| 5226 | 5353 | src, |
| 5227 | 5354 | "unreachable else prong; all cases already handled", |
| 5228 | 5355 | .{}, |
| ... | ... | @@ -5231,8 +5358,8 @@ fn analyzeSwitch( |
| 5231 | 5358 | }, |
| 5232 | 5359 | .under, .none => { |
| 5233 | 5360 | if (true_count + false_count < 2) { |
| 5234 | | return mod.fail( |
| 5235 | | &block.base, |
| 5361 | return sema.fail( |
| 5362 | block, |
| 5236 | 5363 | src, |
| 5237 | 5364 | "switch must handle all possibilities", |
| 5238 | 5365 | .{}, |
| ... | ... | @@ -5243,8 +5370,8 @@ fn analyzeSwitch( |
| 5243 | 5370 | }, |
| 5244 | 5371 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { |
| 5245 | 5372 | if (special_prong != .@"else") { |
| 5246 | | return mod.fail( |
| 5247 | | &block.base, |
| 5373 | return sema.fail( |
| 5374 | block, |
| 5248 | 5375 | src, |
| 5249 | 5376 | "else prong required when switching on type '{}'", |
| 5250 | 5377 | .{operand_ty}, |
| ... | ... | @@ -5314,7 +5441,7 @@ fn analyzeSwitch( |
| 5314 | 5441 | .AnyFrame, |
| 5315 | 5442 | .ComptimeFloat, |
| 5316 | 5443 | .Float, |
| 5317 | | => return mod.fail(&block.base, operand_src, "invalid switch operand type '{}'", .{ |
| 5444 | => return sema.fail(block, operand_src, "invalid switch operand type '{}'", .{ |
| 5318 | 5445 | operand_ty, |
| 5319 | 5446 | }), |
| 5320 | 5447 | } |
| ... | ... | @@ -5707,19 +5834,18 @@ fn validateSwitchItemEnum( |
| 5707 | 5834 | src_node_offset: i32, |
| 5708 | 5835 | switch_prong_src: Module.SwitchProngSrc, |
| 5709 | 5836 | ) CompileError!void { |
| 5710 | | const mod = sema.mod; |
| 5711 | 5837 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 5712 | 5838 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { |
| 5713 | 5839 | const msg = msg: { |
| 5714 | 5840 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5715 | | const msg = try mod.errMsg( |
| 5716 | | &block.base, |
| 5841 | const msg = try sema.errMsg( |
| 5842 | block, |
| 5717 | 5843 | src, |
| 5718 | 5844 | "enum '{}' has no tag with value '{}'", |
| 5719 | 5845 | .{ item_tv.ty, item_tv.val }, |
| 5720 | 5846 | ); |
| 5721 | 5847 | errdefer msg.destroy(sema.gpa); |
| 5722 | | try mod.errNoteNonLazy( |
| 5848 | try sema.mod.errNoteNonLazy( |
| 5723 | 5849 | item_tv.ty.declSrcLoc(), |
| 5724 | 5850 | msg, |
| 5725 | 5851 | "enum declared here", |
| ... | ... | @@ -5727,7 +5853,7 @@ fn validateSwitchItemEnum( |
| 5727 | 5853 | ); |
| 5728 | 5854 | break :msg msg; |
| 5729 | 5855 | }; |
| 5730 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5856 | return sema.failWithOwnedErrorMsg(msg); |
| 5731 | 5857 | }; |
| 5732 | 5858 | const maybe_prev_src = seen_fields[field_index]; |
| 5733 | 5859 | seen_fields[field_index] = switch_prong_src; |
| ... | ... | @@ -5742,20 +5868,19 @@ fn validateSwitchDupe( |
| 5742 | 5868 | src_node_offset: i32, |
| 5743 | 5869 | ) CompileError!void { |
| 5744 | 5870 | const prev_prong_src = maybe_prev_src orelse return; |
| 5745 | | const mod = sema.mod; |
| 5746 | 5871 | const gpa = sema.gpa; |
| 5747 | 5872 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5748 | 5873 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5749 | 5874 | const msg = msg: { |
| 5750 | | const msg = try mod.errMsg( |
| 5751 | | &block.base, |
| 5875 | const msg = try sema.errMsg( |
| 5876 | block, |
| 5752 | 5877 | src, |
| 5753 | 5878 | "duplicate switch value", |
| 5754 | 5879 | .{}, |
| 5755 | 5880 | ); |
| 5756 | 5881 | errdefer msg.destroy(sema.gpa); |
| 5757 | | try mod.errNote( |
| 5758 | | &block.base, |
| 5882 | try sema.errNote( |
| 5883 | block, |
| 5759 | 5884 | prev_src, |
| 5760 | 5885 | msg, |
| 5761 | 5886 | "previous value here", |
| ... | ... | @@ -5763,7 +5888,7 @@ fn validateSwitchDupe( |
| 5763 | 5888 | ); |
| 5764 | 5889 | break :msg msg; |
| 5765 | 5890 | }; |
| 5766 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5891 | return sema.failWithOwnedErrorMsg(msg); |
| 5767 | 5892 | } |
| 5768 | 5893 | |
| 5769 | 5894 | fn validateSwitchItemBool( |
| ... | ... | @@ -5783,7 +5908,7 @@ fn validateSwitchItemBool( |
| 5783 | 5908 | } |
| 5784 | 5909 | if (true_count.* + false_count.* > 2) { |
| 5785 | 5910 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5786 | | return sema.mod.fail(&block.base, src, "duplicate switch value", .{}); |
| 5911 | return sema.fail(block, src, "duplicate switch value", .{}); |
| 5787 | 5912 | } |
| 5788 | 5913 | } |
| 5789 | 5914 | |
| ... | ... | @@ -5816,15 +5941,15 @@ fn validateSwitchNoRange( |
| 5816 | 5941 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; |
| 5817 | 5942 | |
| 5818 | 5943 | const msg = msg: { |
| 5819 | | const msg = try sema.mod.errMsg( |
| 5820 | | &block.base, |
| 5944 | const msg = try sema.errMsg( |
| 5945 | block, |
| 5821 | 5946 | operand_src, |
| 5822 | 5947 | "ranges not allowed when switching on type '{}'", |
| 5823 | 5948 | .{operand_ty}, |
| 5824 | 5949 | ); |
| 5825 | 5950 | errdefer msg.destroy(sema.gpa); |
| 5826 | | try sema.mod.errNote( |
| 5827 | | &block.base, |
| 5951 | try sema.errNote( |
| 5952 | block, |
| 5828 | 5953 | range_src, |
| 5829 | 5954 | msg, |
| 5830 | 5955 | "range here", |
| ... | ... | @@ -5832,7 +5957,7 @@ fn validateSwitchNoRange( |
| 5832 | 5957 | ); |
| 5833 | 5958 | break :msg msg; |
| 5834 | 5959 | }; |
| 5835 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 5960 | return sema.failWithOwnedErrorMsg(msg); |
| 5836 | 5961 | } |
| 5837 | 5962 | |
| 5838 | 5963 | fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -5841,7 +5966,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 5841 | 5966 | _ = extra; |
| 5842 | 5967 | const src = inst_data.src(); |
| 5843 | 5968 | |
| 5844 | | return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{}); |
| 5969 | return sema.fail(block, src, "TODO implement zirHasField", .{}); |
| 5845 | 5970 | } |
| 5846 | 5971 | |
| 5847 | 5972 | fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -5852,10 +5977,9 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 5852 | 5977 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5853 | 5978 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 5854 | 5979 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); |
| 5855 | | const mod = sema.mod; |
| 5856 | 5980 | |
| 5857 | | const namespace = container_type.getNamespace() orelse return mod.fail( |
| 5858 | | &block.base, |
| 5981 | const namespace = container_type.getNamespace() orelse return sema.fail( |
| 5982 | block, |
| 5859 | 5983 | lhs_src, |
| 5860 | 5984 | "expected struct, enum, union, or opaque, found '{}'", |
| 5861 | 5985 | .{container_type}, |
| ... | ... | @@ -5879,24 +6003,24 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 5879 | 6003 | |
| 5880 | 6004 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { |
| 5881 | 6005 | error.ImportOutsidePkgPath => { |
| 5882 | | return mod.fail(&block.base, src, "import of file outside package path: '{s}'", .{operand}); |
| 6006 | return sema.fail(block, src, "import of file outside package path: '{s}'", .{operand}); |
| 5883 | 6007 | }, |
| 5884 | 6008 | else => { |
| 5885 | 6009 | // TODO: these errors are file system errors; make sure an update() will |
| 5886 | 6010 | // retry this and not cache the file system error, which may be transient. |
| 5887 | | return mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 6011 | return sema.fail(block, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 5888 | 6012 | }, |
| 5889 | 6013 | }; |
| 5890 | 6014 | try mod.semaFile(result.file); |
| 5891 | 6015 | const file_root_decl = result.file.root_decl.?; |
| 5892 | | try sema.mod.declareDeclDependency(sema.owner_decl, file_root_decl); |
| 6016 | try mod.declareDeclDependency(sema.owner_decl, file_root_decl); |
| 5893 | 6017 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); |
| 5894 | 6018 | } |
| 5895 | 6019 | |
| 5896 | 6020 | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5897 | 6021 | _ = block; |
| 5898 | 6022 | _ = inst; |
| 5899 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{}); |
| 6023 | return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{}); |
| 5900 | 6024 | } |
| 5901 | 6025 | |
| 5902 | 6026 | fn zirShl( |
| ... | ... | @@ -5933,8 +6057,8 @@ fn zirShl( |
| 5933 | 6057 | } |
| 5934 | 6058 | const val = try lhs_val.shl(rhs_val, sema.arena); |
| 5935 | 6059 | switch (air_tag) { |
| 5936 | | .shl_exact => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), |
| 5937 | | .shl_sat => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 6060 | .shl_exact => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), |
| 6061 | .shl_sat => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 5938 | 6062 | .shl => {}, |
| 5939 | 6063 | else => unreachable, |
| 5940 | 6064 | } |
| ... | ... | @@ -6016,14 +6140,14 @@ fn zirBitwise( |
| 6016 | 6140 | |
| 6017 | 6141 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 6018 | 6142 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 6019 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 6143 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 6020 | 6144 | lhs_ty.arrayLen(), |
| 6021 | 6145 | rhs_ty.arrayLen(), |
| 6022 | 6146 | }); |
| 6023 | 6147 | } |
| 6024 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in zirBitwise", .{}); |
| 6148 | return sema.fail(block, src, "TODO implement support for vectors in zirBitwise", .{}); |
| 6025 | 6149 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { |
| 6026 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6150 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6027 | 6151 | lhs_ty, |
| 6028 | 6152 | rhs_ty, |
| 6029 | 6153 | }); |
| ... | ... | @@ -6032,7 +6156,7 @@ fn zirBitwise( |
| 6032 | 6156 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; |
| 6033 | 6157 | |
| 6034 | 6158 | if (!is_int) { |
| 6035 | | return sema.mod.fail(&block.base, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) }); |
| 6159 | return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) }); |
| 6036 | 6160 | } |
| 6037 | 6161 | |
| 6038 | 6162 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { |
| ... | ... | @@ -6056,7 +6180,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 6056 | 6180 | defer tracy.end(); |
| 6057 | 6181 | |
| 6058 | 6182 | _ = inst; |
| 6059 | | return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{}); |
| 6183 | return sema.fail(block, sema.src, "TODO implement zirBitNot", .{}); |
| 6060 | 6184 | } |
| 6061 | 6185 | |
| 6062 | 6186 | fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -6073,11 +6197,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6073 | 6197 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 6074 | 6198 | |
| 6075 | 6199 | const lhs_info = getArrayCatInfo(lhs_ty) orelse |
| 6076 | | return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6200 | return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6077 | 6201 | const rhs_info = getArrayCatInfo(rhs_ty) orelse |
| 6078 | | return sema.mod.fail(&block.base, rhs_src, "expected array, found '{}'", .{rhs_ty}); |
| 6202 | return sema.fail(block, rhs_src, "expected array, found '{}'", .{rhs_ty}); |
| 6079 | 6203 | if (!lhs_info.elem_type.eql(rhs_info.elem_type)) { |
| 6080 | | return sema.mod.fail(&block.base, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty }); |
| 6204 | return sema.fail(block, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty }); |
| 6081 | 6205 | } |
| 6082 | 6206 | |
| 6083 | 6207 | // When there is a sentinel mismatch, no sentinel on the result. The type system |
| ... | ... | @@ -6123,10 +6247,10 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6123 | 6247 | else |
| 6124 | 6248 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); |
| 6125 | 6249 | } else { |
| 6126 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{}); |
| 6250 | return sema.fail(block, lhs_src, "TODO runtime array_cat", .{}); |
| 6127 | 6251 | } |
| 6128 | 6252 | } else { |
| 6129 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{}); |
| 6253 | return sema.fail(block, lhs_src, "TODO runtime array_cat", .{}); |
| 6130 | 6254 | } |
| 6131 | 6255 | } |
| 6132 | 6256 | |
| ... | ... | @@ -6157,9 +6281,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6157 | 6281 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known |
| 6158 | 6282 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); |
| 6159 | 6283 | const mulinfo = getArrayCatInfo(lhs_ty) orelse |
| 6160 | | return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6284 | return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty}); |
| 6161 | 6285 | |
| 6162 | | const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.mod.fail(&block.base, rhs_src, "operation results in overflow", .{}); |
| 6286 | const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.fail(block, rhs_src, "operation results in overflow", .{}); |
| 6163 | 6287 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { |
| 6164 | 6288 | var anon_decl = try block.startAnonDecl(); |
| 6165 | 6289 | defer anon_decl.deinit(); |
| ... | ... | @@ -6192,7 +6316,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6192 | 6316 | return sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(final_ty, val)); |
| 6193 | 6317 | } |
| 6194 | 6318 | } |
| 6195 | | return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_mul", .{}); |
| 6319 | return sema.fail(block, lhs_src, "TODO runtime array_mul", .{}); |
| 6196 | 6320 | } |
| 6197 | 6321 | |
| 6198 | 6322 | fn zirNegate( |
| ... | ... | @@ -6245,7 +6369,7 @@ fn zirOverflowArithmetic( |
| 6245 | 6369 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; |
| 6246 | 6370 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 6247 | 6371 | |
| 6248 | | return sema.mod.fail(&block.base, src, "TODO implement Sema.zirOverflowArithmetic", .{}); |
| 6372 | return sema.fail(block, src, "TODO implement Sema.zirOverflowArithmetic", .{}); |
| 6249 | 6373 | } |
| 6250 | 6374 | |
| 6251 | 6375 | fn analyzeArithmetic( |
| ... | ... | @@ -6265,13 +6389,13 @@ fn analyzeArithmetic( |
| 6265 | 6389 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); |
| 6266 | 6390 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { |
| 6267 | 6391 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 6268 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 6392 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 6269 | 6393 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), |
| 6270 | 6394 | }); |
| 6271 | 6395 | } |
| 6272 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{}); |
| 6396 | return sema.fail(block, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{}); |
| 6273 | 6397 | } else if (lhs_zig_ty_tag == .Vector or rhs_zig_ty_tag == .Vector) { |
| 6274 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6398 | return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{ |
| 6275 | 6399 | lhs_ty, rhs_ty, |
| 6276 | 6400 | }); |
| 6277 | 6401 | } |
| ... | ... | @@ -6283,8 +6407,8 @@ fn analyzeArithmetic( |
| 6283 | 6407 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 6284 | 6408 | .add => .ptr_add, |
| 6285 | 6409 | .sub => .ptr_sub, |
| 6286 | | else => return sema.mod.fail( |
| 6287 | | &block.base, |
| 6410 | else => return sema.fail( |
| 6411 | block, |
| 6288 | 6412 | op_src, |
| 6289 | 6413 | "invalid pointer arithmetic operand: '{s}''", |
| 6290 | 6414 | .{@tagName(zir_tag)}, |
| ... | ... | @@ -6298,7 +6422,7 @@ fn analyzeArithmetic( |
| 6298 | 6422 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { |
| 6299 | 6423 | _ = lhs_val; |
| 6300 | 6424 | _ = rhs_val; |
| 6301 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for comptime pointer arithmetic", .{}); |
| 6425 | return sema.fail(block, src, "TODO implement Sema for comptime pointer arithmetic", .{}); |
| 6302 | 6426 | } else { |
| 6303 | 6427 | break :runtime_src rhs_src; |
| 6304 | 6428 | } |
| ... | ... | @@ -6329,7 +6453,7 @@ fn analyzeArithmetic( |
| 6329 | 6453 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; |
| 6330 | 6454 | |
| 6331 | 6455 | if (!is_int and !(is_float and floatOpAllowed(zir_tag))) { |
| 6332 | | return sema.mod.fail(&block.base, src, "invalid operands to binary expression: '{s}' and '{s}'", .{ |
| 6456 | return sema.fail(block, src, "invalid operands to binary expression: '{s}' and '{s}'", .{ |
| 6333 | 6457 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), |
| 6334 | 6458 | }); |
| 6335 | 6459 | } |
| ... | ... | @@ -6939,7 +7063,7 @@ fn zirAsm( |
| 6939 | 7063 | const clobbers_len = @truncate(u5, extended.small >> 10); |
| 6940 | 7064 | |
| 6941 | 7065 | if (outputs_len > 1) { |
| 6942 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with more than 1 output", .{}); |
| 7066 | return sema.fail(block, src, "TODO implement Sema for asm with more than 1 output", .{}); |
| 6943 | 7067 | } |
| 6944 | 7068 | |
| 6945 | 7069 | var extra_i = extra.end; |
| ... | ... | @@ -6954,7 +7078,7 @@ fn zirAsm( |
| 6954 | 7078 | output_type_bits >>= 1; |
| 6955 | 7079 | |
| 6956 | 7080 | if (!is_type) { |
| 6957 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with non `->` output", .{}); |
| 7081 | return sema.fail(block, src, "TODO implement Sema for asm with non `->` output", .{}); |
| 6958 | 7082 | } |
| 6959 | 7083 | |
| 6960 | 7084 | const constraint = sema.code.nullTerminatedString(output.data.constraint); |
| ... | ... | @@ -7011,7 +7135,6 @@ fn zirCmpEq( |
| 7011 | 7135 | const tracy = trace(@src()); |
| 7012 | 7136 | defer tracy.end(); |
| 7013 | 7137 | |
| 7014 | | const mod = sema.mod; |
| 7015 | 7138 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 7016 | 7139 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 7017 | 7140 | const src: LazySrcLoc = inst_data.src(); |
| ... | ... | @@ -7040,11 +7163,11 @@ fn zirCmpEq( |
| 7040 | 7163 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); |
| 7041 | 7164 | } |
| 7042 | 7165 | if (((lhs_ty_tag == .Null and rhs_ty.isCPtr()) or (rhs_ty_tag == .Null and lhs_ty.isCPtr()))) { |
| 7043 | | return mod.fail(&block.base, src, "TODO implement C pointer cmp", .{}); |
| 7166 | return sema.fail(block, src, "TODO implement C pointer cmp", .{}); |
| 7044 | 7167 | } |
| 7045 | 7168 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { |
| 7046 | 7169 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; |
| 7047 | | return mod.fail(&block.base, src, "comparison of '{}' with null", .{non_null_type}); |
| 7170 | return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type}); |
| 7048 | 7171 | } |
| 7049 | 7172 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { |
| 7050 | 7173 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); |
| ... | ... | @@ -7103,7 +7226,7 @@ fn analyzeCmpUnionTag( |
| 7103 | 7226 | const union_ty = sema.typeOf(un); |
| 7104 | 7227 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 7105 | 7228 | // TODO note at declaration site that says "union foo is not tagged" |
| 7106 | | return sema.mod.fail(&block.base, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 7229 | return sema.fail(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 7107 | 7230 | }; |
| 7108 | 7231 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 7109 | 7232 | // enum comparison codepath. |
| ... | ... | @@ -7155,7 +7278,7 @@ fn analyzeCmp( |
| 7155 | 7278 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; |
| 7156 | 7279 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); |
| 7157 | 7280 | if (!resolved_type.isSelfComparable(is_equality_cmp)) { |
| 7158 | | return sema.mod.fail(&block.base, src, "{s} operator not allowed for type '{}'", .{ |
| 7281 | return sema.fail(block, src, "{s} operator not allowed for type '{}'", .{ |
| 7159 | 7282 | @tagName(op), resolved_type, |
| 7160 | 7283 | }); |
| 7161 | 7284 | } |
| ... | ... | @@ -7252,7 +7375,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7252 | 7375 | .Null, |
| 7253 | 7376 | .BoundFn, |
| 7254 | 7377 | .Opaque, |
| 7255 | | => return sema.mod.fail(&block.base, src, "no size available for type '{}'", .{operand_ty}), |
| 7378 | => return sema.fail(block, src, "no size available for type '{}'", .{operand_ty}), |
| 7256 | 7379 | .Type, |
| 7257 | 7380 | .EnumLiteral, |
| 7258 | 7381 | .ComptimeFloat, |
| ... | ... | @@ -7340,7 +7463,7 @@ fn zirRetAddr( |
| 7340 | 7463 | extended: Zir.Inst.Extended.InstData, |
| 7341 | 7464 | ) CompileError!Air.Inst.Ref { |
| 7342 | 7465 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7343 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 7466 | return sema.fail(block, src, "TODO: implement Sema.zirRetAddr", .{}); |
| 7344 | 7467 | } |
| 7345 | 7468 | |
| 7346 | 7469 | fn zirBuiltinSrc( |
| ... | ... | @@ -7349,7 +7472,7 @@ fn zirBuiltinSrc( |
| 7349 | 7472 | extended: Zir.Inst.Extended.InstData, |
| 7350 | 7473 | ) CompileError!Air.Inst.Ref { |
| 7351 | 7474 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 7352 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 7475 | return sema.fail(block, src, "TODO: implement Sema.zirBuiltinSrc", .{}); |
| 7353 | 7476 | } |
| 7354 | 7477 | |
| 7355 | 7478 | fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -7551,7 +7674,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 7551 | 7674 | }), |
| 7552 | 7675 | ); |
| 7553 | 7676 | }, |
| 7554 | | else => |t| return sema.mod.fail(&block.base, src, "TODO: implement zirTypeInfo for {s}", .{ |
| 7677 | else => |t| return sema.fail(block, src, "TODO: implement zirTypeInfo for {s}", .{ |
| 7555 | 7678 | @tagName(t), |
| 7556 | 7679 | }), |
| 7557 | 7680 | } |
| ... | ... | @@ -7601,8 +7724,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7601 | 7724 | const res = try Module.makeIntType(sema.arena, .unsigned, count); |
| 7602 | 7725 | return sema.addType(res); |
| 7603 | 7726 | }, |
| 7604 | | else => return sema.mod.fail( |
| 7605 | | &block.base, |
| 7727 | else => return sema.fail( |
| 7728 | block, |
| 7606 | 7729 | src, |
| 7607 | 7730 | "bit shifting operation expected integer type, found '{}'", |
| 7608 | 7731 | .{operand}, |
| ... | ... | @@ -8026,7 +8149,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8026 | 8149 | } else 0; |
| 8027 | 8150 | |
| 8028 | 8151 | if (bit_end != 0 and bit_start >= bit_end * 8) |
| 8029 | | return sema.mod.fail(&block.base, src, "bit offset starts after end of host integer", .{}); |
| 8152 | return sema.fail(block, src, "bit offset starts after end of host integer", .{}); |
| 8030 | 8153 | |
| 8031 | 8154 | const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type); |
| 8032 | 8155 | |
| ... | ... | @@ -8059,11 +8182,10 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 8059 | 8182 | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8060 | 8183 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8061 | 8184 | const src = inst_data.src(); |
| 8062 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{}); |
| 8185 | return sema.fail(block, src, "TODO: Sema.zirUnionInitPtr", .{}); |
| 8063 | 8186 | } |
| 8064 | 8187 | |
| 8065 | 8188 | fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| 8066 | | const mod = sema.mod; |
| 8067 | 8189 | const gpa = sema.gpa; |
| 8068 | 8190 | const zir_datas = sema.code.instructions.items(.data); |
| 8069 | 8191 | const inst_data = zir_datas[inst].pl_node; |
| ... | ... | @@ -8107,12 +8229,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8107 | 8229 | const other_field_type_data = zir_datas[other_field_type].pl_node; |
| 8108 | 8230 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; |
| 8109 | 8231 | const msg = msg: { |
| 8110 | | const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{}); |
| 8232 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 8111 | 8233 | errdefer msg.destroy(gpa); |
| 8112 | | try mod.errNote(&block.base, other_field_src, msg, "other field here", .{}); |
| 8234 | try sema.errNote(block, other_field_src, msg, "other field here", .{}); |
| 8113 | 8235 | break :msg msg; |
| 8114 | 8236 | }; |
| 8115 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 8237 | return sema.failWithOwnedErrorMsg(msg); |
| 8116 | 8238 | } |
| 8117 | 8239 | found_fields[field_index] = item.data.field_type; |
| 8118 | 8240 | field_inits[field_index] = sema.resolveInst(item.data.init); |
| ... | ... | @@ -8130,9 +8252,9 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8130 | 8252 | const template = "missing struct field: {s}"; |
| 8131 | 8253 | const args = .{field_name}; |
| 8132 | 8254 | if (root_msg) |msg| { |
| 8133 | | try mod.errNote(&block.base, src, msg, template, args); |
| 8255 | try sema.errNote(block, src, msg, template, args); |
| 8134 | 8256 | } else { |
| 8135 | | root_msg = try mod.errMsg(&block.base, src, template, args); |
| 8257 | root_msg = try sema.errMsg(block, src, template, args); |
| 8136 | 8258 | } |
| 8137 | 8259 | } else { |
| 8138 | 8260 | field_inits[i] = try sema.addConstant(field.ty, field.default_val); |
| ... | ... | @@ -8141,17 +8263,17 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8141 | 8263 | if (root_msg) |msg| { |
| 8142 | 8264 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 8143 | 8265 | defer gpa.free(fqn); |
| 8144 | | try mod.errNoteNonLazy( |
| 8266 | try sema.mod.errNoteNonLazy( |
| 8145 | 8267 | struct_obj.srcLoc(), |
| 8146 | 8268 | msg, |
| 8147 | 8269 | "struct '{s}' declared here", |
| 8148 | 8270 | .{fqn}, |
| 8149 | 8271 | ); |
| 8150 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 8272 | return sema.failWithOwnedErrorMsg(msg); |
| 8151 | 8273 | } |
| 8152 | 8274 | |
| 8153 | 8275 | if (is_ref) { |
| 8154 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{}); |
| 8276 | return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true", .{}); |
| 8155 | 8277 | } |
| 8156 | 8278 | |
| 8157 | 8279 | const is_comptime = for (field_inits) |field_init| { |
| ... | ... | @@ -8168,12 +8290,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8168 | 8290 | return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values)); |
| 8169 | 8291 | } |
| 8170 | 8292 | |
| 8171 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{}); |
| 8293 | return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{}); |
| 8172 | 8294 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { |
| 8173 | 8295 | const union_obj = union_payload.data; |
| 8174 | 8296 | |
| 8175 | 8297 | if (extra.data.fields_len != 1) { |
| 8176 | | return sema.mod.fail(&block.base, src, "union initialization expects exactly one field", .{}); |
| 8298 | return sema.fail(block, src, "union initialization expects exactly one field", .{}); |
| 8177 | 8299 | } |
| 8178 | 8300 | |
| 8179 | 8301 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| ... | ... | @@ -8186,7 +8308,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8186 | 8308 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| 8187 | 8309 | |
| 8188 | 8310 | if (is_ref) { |
| 8189 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true union", .{}); |
| 8311 | return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true union", .{}); |
| 8190 | 8312 | } |
| 8191 | 8313 | |
| 8192 | 8314 | const init_inst = sema.resolveInst(item.data.init); |
| ... | ... | @@ -8199,7 +8321,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8199 | 8321 | }), |
| 8200 | 8322 | ); |
| 8201 | 8323 | } |
| 8202 | | return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known union values", .{}); |
| 8324 | return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known union values", .{}); |
| 8203 | 8325 | } |
| 8204 | 8326 | unreachable; |
| 8205 | 8327 | } |
| ... | ... | @@ -8209,7 +8331,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ |
| 8209 | 8331 | const src = inst_data.src(); |
| 8210 | 8332 | |
| 8211 | 8333 | _ = is_ref; |
| 8212 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 8334 | return sema.fail(block, src, "TODO: Sema.zirStructInitAnon", .{}); |
| 8213 | 8335 | } |
| 8214 | 8336 | |
| 8215 | 8337 | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8269,13 +8391,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r |
| 8269 | 8391 | const src = inst_data.src(); |
| 8270 | 8392 | |
| 8271 | 8393 | _ = is_ref; |
| 8272 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{}); |
| 8394 | return sema.fail(block, src, "TODO: Sema.zirArrayInitAnon", .{}); |
| 8273 | 8395 | } |
| 8274 | 8396 | |
| 8275 | 8397 | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8276 | 8398 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8277 | 8399 | const src = inst_data.src(); |
| 8278 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{}); |
| 8400 | return sema.fail(block, src, "TODO: Sema.zirFieldTypeRef", .{}); |
| 8279 | 8401 | } |
| 8280 | 8402 | |
| 8281 | 8403 | fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8298,7 +8420,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8298 | 8420 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); |
| 8299 | 8421 | return sema.addType(field.ty); |
| 8300 | 8422 | }, |
| 8301 | | else => return sema.mod.fail(&block.base, src, "expected struct or union; found '{}'", .{ |
| 8423 | else => return sema.fail(block, src, "expected struct or union; found '{}'", .{ |
| 8302 | 8424 | resolved_ty, |
| 8303 | 8425 | }), |
| 8304 | 8426 | } |
| ... | ... | @@ -8310,7 +8432,7 @@ fn zirErrorReturnTrace( |
| 8310 | 8432 | extended: Zir.Inst.Extended.InstData, |
| 8311 | 8433 | ) CompileError!Air.Inst.Ref { |
| 8312 | 8434 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8313 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 8435 | return sema.fail(block, src, "TODO: Sema.zirErrorReturnTrace", .{}); |
| 8314 | 8436 | } |
| 8315 | 8437 | |
| 8316 | 8438 | fn zirFrame( |
| ... | ... | @@ -8319,7 +8441,7 @@ fn zirFrame( |
| 8319 | 8441 | extended: Zir.Inst.Extended.InstData, |
| 8320 | 8442 | ) CompileError!Air.Inst.Ref { |
| 8321 | 8443 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8322 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{}); |
| 8444 | return sema.fail(block, src, "TODO: Sema.zirFrame", .{}); |
| 8323 | 8445 | } |
| 8324 | 8446 | |
| 8325 | 8447 | fn zirFrameAddress( |
| ... | ... | @@ -8328,7 +8450,7 @@ fn zirFrameAddress( |
| 8328 | 8450 | extended: Zir.Inst.Extended.InstData, |
| 8329 | 8451 | ) CompileError!Air.Inst.Ref { |
| 8330 | 8452 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; |
| 8331 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{}); |
| 8453 | return sema.fail(block, src, "TODO: Sema.zirFrameAddress", .{}); |
| 8332 | 8454 | } |
| 8333 | 8455 | |
| 8334 | 8456 | fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8355,25 +8477,25 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8355 | 8477 | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8356 | 8478 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8357 | 8479 | const src = inst_data.src(); |
| 8358 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{}); |
| 8480 | return sema.fail(block, src, "TODO: Sema.zirEmbedFile", .{}); |
| 8359 | 8481 | } |
| 8360 | 8482 | |
| 8361 | 8483 | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8362 | 8484 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8363 | 8485 | const src = inst_data.src(); |
| 8364 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{}); |
| 8486 | return sema.fail(block, src, "TODO: Sema.zirErrorName", .{}); |
| 8365 | 8487 | } |
| 8366 | 8488 | |
| 8367 | 8489 | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8368 | 8490 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8369 | 8491 | const src = inst_data.src(); |
| 8370 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{}); |
| 8492 | return sema.fail(block, src, "TODO: Sema.zirUnaryMath", .{}); |
| 8371 | 8493 | } |
| 8372 | 8494 | |
| 8373 | 8495 | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8374 | 8496 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8375 | 8497 | const src = inst_data.src(); |
| 8376 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{}); |
| 8498 | return sema.fail(block, src, "TODO: Sema.zirTagName", .{}); |
| 8377 | 8499 | } |
| 8378 | 8500 | |
| 8379 | 8501 | fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8406,25 +8528,25 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8406 | 8528 | }; |
| 8407 | 8529 | return sema.addType(ty); |
| 8408 | 8530 | }, |
| 8409 | | .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}), |
| 8410 | | .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8411 | | .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}), |
| 8412 | | .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8531 | .Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}), |
| 8532 | .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8533 | .Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}), |
| 8534 | .Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8413 | 8535 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, |
| 8414 | 8536 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 8415 | 8537 | .Undefined => return Air.Inst.Ref.undefined_type, |
| 8416 | 8538 | .Null => return Air.Inst.Ref.null_type, |
| 8417 | | .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8418 | | .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8419 | | .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8420 | | .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8421 | | .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}), |
| 8422 | | .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8539 | .Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8540 | .ErrorUnion => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8541 | .ErrorSet => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8542 | .Enum => return sema.fail(block, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8543 | .Union => return sema.fail(block, src, "TODO: Sema.zirReify for Union", .{}), |
| 8544 | .Fn => return sema.fail(block, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8423 | 8545 | .BoundFn => @panic("TODO delete BoundFn from the language"), |
| 8424 | | .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8425 | | .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8546 | .Opaque => return sema.fail(block, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8547 | .Frame => return sema.fail(block, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8426 | 8548 | .AnyFrame => return Air.Inst.Ref.anyframe_type, |
| 8427 | | .Vector => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Vector", .{}), |
| 8549 | .Vector => return sema.fail(block, src, "TODO: Sema.zirReify for Vector", .{}), |
| 8428 | 8550 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, |
| 8429 | 8551 | } |
| 8430 | 8552 | } |
| ... | ... | @@ -8432,26 +8554,26 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8432 | 8554 | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8433 | 8555 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8434 | 8556 | const src = inst_data.src(); |
| 8435 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{}); |
| 8557 | return sema.fail(block, src, "TODO: Sema.zirTypeName", .{}); |
| 8436 | 8558 | } |
| 8437 | 8559 | |
| 8438 | 8560 | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8439 | 8561 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8440 | 8562 | const src = inst_data.src(); |
| 8441 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{}); |
| 8563 | return sema.fail(block, src, "TODO: Sema.zirFrameType", .{}); |
| 8442 | 8564 | } |
| 8443 | 8565 | |
| 8444 | 8566 | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8445 | 8567 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8446 | 8568 | const src = inst_data.src(); |
| 8447 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{}); |
| 8569 | return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{}); |
| 8448 | 8570 | } |
| 8449 | 8571 | |
| 8450 | 8572 | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8451 | 8573 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8452 | 8574 | const src = inst_data.src(); |
| 8453 | 8575 | // TODO don't forget the safety check! |
| 8454 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{}); |
| 8576 | return sema.fail(block, src, "TODO: Sema.zirFloatToInt", .{}); |
| 8455 | 8577 | } |
| 8456 | 8578 | |
| 8457 | 8579 | fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8489,15 +8611,15 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8489 | 8611 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8490 | 8612 | const type_res = try sema.resolveType(block, src, extra.lhs); |
| 8491 | 8613 | if (type_res.zigTypeTag() != .Pointer) |
| 8492 | | return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res}); |
| 8614 | return sema.fail(block, type_src, "expected pointer, found '{}'", .{type_res}); |
| 8493 | 8615 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); |
| 8494 | 8616 | |
| 8495 | 8617 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 8496 | 8618 | const addr = val.toUnsignedInt(); |
| 8497 | 8619 | if (!type_res.isAllowzeroPtr() and addr == 0) |
| 8498 | | return sema.mod.fail(&block.base, operand_src, "pointer type '{}' does not allow address zero", .{type_res}); |
| 8620 | return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{type_res}); |
| 8499 | 8621 | if (addr != 0 and addr % ptr_align != 0) |
| 8500 | | return sema.mod.fail(&block.base, operand_src, "pointer type '{}' requires aligned address", .{type_res}); |
| 8622 | return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{type_res}); |
| 8501 | 8623 | |
| 8502 | 8624 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 8503 | 8625 | val_payload.* = .{ |
| ... | ... | @@ -8535,7 +8657,7 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8535 | 8657 | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8536 | 8658 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8537 | 8659 | const src = inst_data.src(); |
| 8538 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{}); |
| 8660 | return sema.fail(block, src, "TODO: Sema.zirErrSetCast", .{}); |
| 8539 | 8661 | } |
| 8540 | 8662 | |
| 8541 | 8663 | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8547,12 +8669,12 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8547 | 8669 | const operand = sema.resolveInst(extra.rhs); |
| 8548 | 8670 | const operand_ty = sema.typeOf(operand); |
| 8549 | 8671 | if (operand_ty.zigTypeTag() != .Pointer) { |
| 8550 | | return sema.mod.fail(&block.base, operand_src, "expected pointer, found {s} type '{}'", .{ |
| 8672 | return sema.fail(block, operand_src, "expected pointer, found {s} type '{}'", .{ |
| 8551 | 8673 | @tagName(operand_ty.zigTypeTag()), operand_ty, |
| 8552 | 8674 | }); |
| 8553 | 8675 | } |
| 8554 | 8676 | if (dest_ty.zigTypeTag() != .Pointer) { |
| 8555 | | return sema.mod.fail(&block.base, dest_ty_src, "expected pointer, found {s} type '{}'", .{ |
| 8677 | return sema.fail(block, dest_ty_src, "expected pointer, found {s} type '{}'", .{ |
| 8556 | 8678 | @tagName(dest_ty.zigTypeTag()), dest_ty, |
| 8557 | 8679 | }); |
| 8558 | 8680 | } |
| ... | ... | @@ -8571,7 +8693,6 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8571 | 8693 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 8572 | 8694 | const operand = sema.resolveInst(extra.rhs); |
| 8573 | 8695 | const operand_ty = sema.typeOf(operand); |
| 8574 | | const mod = sema.mod; |
| 8575 | 8696 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); |
| 8576 | 8697 | const src_is_comptime_int = try sema.checkIntType(block, operand_src, operand_ty); |
| 8577 | 8698 | |
| ... | ... | @@ -8579,7 +8700,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8579 | 8700 | return sema.coerce(block, dest_ty, operand, operand_src); |
| 8580 | 8701 | } |
| 8581 | 8702 | |
| 8582 | | const target = mod.getTarget(); |
| 8703 | const target = sema.mod.getTarget(); |
| 8583 | 8704 | const src_info = operand_ty.intInfo(target); |
| 8584 | 8705 | const dest_info = dest_ty.intInfo(target); |
| 8585 | 8706 | |
| ... | ... | @@ -8589,28 +8710,28 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8589 | 8710 | |
| 8590 | 8711 | if (!src_is_comptime_int) { |
| 8591 | 8712 | if (src_info.signedness != dest_info.signedness) { |
| 8592 | | return mod.fail(&block.base, operand_src, "expected {s} integer type, found '{}'", .{ |
| 8713 | return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{ |
| 8593 | 8714 | @tagName(dest_info.signedness), operand_ty, |
| 8594 | 8715 | }); |
| 8595 | 8716 | } |
| 8596 | 8717 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { |
| 8597 | 8718 | const msg = msg: { |
| 8598 | | const msg = try mod.errMsg( |
| 8599 | | &block.base, |
| 8719 | const msg = try sema.errMsg( |
| 8720 | block, |
| 8600 | 8721 | src, |
| 8601 | 8722 | "destination type '{}' has more bits than source type '{}'", |
| 8602 | 8723 | .{ dest_ty, operand_ty }, |
| 8603 | 8724 | ); |
| 8604 | | errdefer msg.destroy(mod.gpa); |
| 8605 | | try mod.errNote(&block.base, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 8725 | errdefer msg.destroy(sema.gpa); |
| 8726 | try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 8606 | 8727 | dest_info.bits, |
| 8607 | 8728 | }); |
| 8608 | | try mod.errNote(&block.base, operand_src, msg, "source type has {d} bits", .{ |
| 8729 | try sema.errNote(block, operand_src, msg, "source type has {d} bits", .{ |
| 8609 | 8730 | src_info.bits, |
| 8610 | 8731 | }); |
| 8611 | 8732 | break :msg msg; |
| 8612 | 8733 | }; |
| 8613 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 8734 | return sema.failWithOwnedErrorMsg(msg); |
| 8614 | 8735 | } |
| 8615 | 8736 | } |
| 8616 | 8737 | |
| ... | ... | @@ -8626,7 +8747,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8626 | 8747 | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8627 | 8748 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8628 | 8749 | const src = inst_data.src(); |
| 8629 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{}); |
| 8750 | return sema.fail(block, src, "TODO: Sema.zirAlignCast", .{}); |
| 8630 | 8751 | } |
| 8631 | 8752 | |
| 8632 | 8753 | fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8637,7 +8758,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8637 | 8758 | const operand_ty = sema.typeOf(operand); |
| 8638 | 8759 | // TODO implement support for vectors |
| 8639 | 8760 | if (operand_ty.zigTypeTag() != .Int) { |
| 8640 | | return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{ |
| 8761 | return sema.fail(block, ty_src, "expected integer type, found '{}'", .{ |
| 8641 | 8762 | operand_ty, |
| 8642 | 8763 | }); |
| 8643 | 8764 | } |
| ... | ... | @@ -8664,7 +8785,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8664 | 8785 | const operand_ty = sema.typeOf(operand); |
| 8665 | 8786 | // TODO implement support for vectors |
| 8666 | 8787 | if (operand_ty.zigTypeTag() != .Int) { |
| 8667 | | return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{ |
| 8788 | return sema.fail(block, ty_src, "expected integer type, found '{}'", .{ |
| 8668 | 8789 | operand_ty, |
| 8669 | 8790 | }); |
| 8670 | 8791 | } |
| ... | ... | @@ -8676,7 +8797,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8676 | 8797 | |
| 8677 | 8798 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 8678 | 8799 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 8679 | | return sema.mod.fail(&block.base, operand_src, "TODO: implement comptime @ctz", .{}); |
| 8800 | return sema.fail(block, operand_src, "TODO: implement comptime @ctz", .{}); |
| 8680 | 8801 | } else operand_src; |
| 8681 | 8802 | |
| 8682 | 8803 | try sema.requireRuntimeBlock(block, runtime_src); |
| ... | ... | @@ -8686,55 +8807,55 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8686 | 8807 | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8687 | 8808 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8688 | 8809 | const src = inst_data.src(); |
| 8689 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{}); |
| 8810 | return sema.fail(block, src, "TODO: Sema.zirPopCount", .{}); |
| 8690 | 8811 | } |
| 8691 | 8812 | |
| 8692 | 8813 | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8693 | 8814 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8694 | 8815 | const src = inst_data.src(); |
| 8695 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{}); |
| 8816 | return sema.fail(block, src, "TODO: Sema.zirByteSwap", .{}); |
| 8696 | 8817 | } |
| 8697 | 8818 | |
| 8698 | 8819 | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8699 | 8820 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8700 | 8821 | const src = inst_data.src(); |
| 8701 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{}); |
| 8822 | return sema.fail(block, src, "TODO: Sema.zirBitReverse", .{}); |
| 8702 | 8823 | } |
| 8703 | 8824 | |
| 8704 | 8825 | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8705 | 8826 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8706 | 8827 | const src = inst_data.src(); |
| 8707 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{}); |
| 8828 | return sema.fail(block, src, "TODO: Sema.zirDivExact", .{}); |
| 8708 | 8829 | } |
| 8709 | 8830 | |
| 8710 | 8831 | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8711 | 8832 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8712 | 8833 | const src = inst_data.src(); |
| 8713 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{}); |
| 8834 | return sema.fail(block, src, "TODO: Sema.zirDivFloor", .{}); |
| 8714 | 8835 | } |
| 8715 | 8836 | |
| 8716 | 8837 | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8717 | 8838 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8718 | 8839 | const src = inst_data.src(); |
| 8719 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{}); |
| 8840 | return sema.fail(block, src, "TODO: Sema.zirDivTrunc", .{}); |
| 8720 | 8841 | } |
| 8721 | 8842 | |
| 8722 | 8843 | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8723 | 8844 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8724 | 8845 | const src = inst_data.src(); |
| 8725 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{}); |
| 8846 | return sema.fail(block, src, "TODO: Sema.zirShrExact", .{}); |
| 8726 | 8847 | } |
| 8727 | 8848 | |
| 8728 | 8849 | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8729 | 8850 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8730 | 8851 | const src = inst_data.src(); |
| 8731 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{}); |
| 8852 | return sema.fail(block, src, "TODO: Sema.zirBitOffsetOf", .{}); |
| 8732 | 8853 | } |
| 8733 | 8854 | |
| 8734 | 8855 | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8735 | 8856 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8736 | 8857 | const src = inst_data.src(); |
| 8737 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{}); |
| 8858 | return sema.fail(block, src, "TODO: Sema.zirOffsetOf", .{}); |
| 8738 | 8859 | } |
| 8739 | 8860 | |
| 8740 | 8861 | /// Returns `true` if the type was a comptime_int. |
| ... | ... | @@ -8742,7 +8863,7 @@ fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) Com |
| 8742 | 8863 | switch (ty.zigTypeTag()) { |
| 8743 | 8864 | .ComptimeInt => return true, |
| 8744 | 8865 | .Int => return false, |
| 8745 | | else => return sema.mod.fail(&block.base, src, "expected integer type, found '{}'", .{ty}), |
| 8866 | else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty}), |
| 8746 | 8867 | } |
| 8747 | 8868 | } |
| 8748 | 8869 | |
| ... | ... | @@ -8754,7 +8875,7 @@ fn checkFloatType( |
| 8754 | 8875 | ) CompileError!void { |
| 8755 | 8876 | switch (ty.zigTypeTag()) { |
| 8756 | 8877 | .ComptimeFloat, .Float => {}, |
| 8757 | | else => return sema.mod.fail(&block.base, ty_src, "expected float type, found '{}'", .{ |
| 8878 | else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ |
| 8758 | 8879 | ty, |
| 8759 | 8880 | }), |
| 8760 | 8881 | } |
| ... | ... | @@ -8775,8 +8896,8 @@ fn checkAtomicOperandType( |
| 8775 | 8896 | .Float => { |
| 8776 | 8897 | const bit_count = ty.floatBits(target); |
| 8777 | 8898 | if (bit_count > max_atomic_bits) { |
| 8778 | | return sema.mod.fail( |
| 8779 | | &block.base, |
| 8899 | return sema.fail( |
| 8900 | block, |
| 8780 | 8901 | ty_src, |
| 8781 | 8902 | "expected {d}-bit float type or smaller; found {d}-bit float type", |
| 8782 | 8903 | .{ max_atomic_bits, bit_count }, |
| ... | ... | @@ -8788,8 +8909,8 @@ fn checkAtomicOperandType( |
| 8788 | 8909 | else => { |
| 8789 | 8910 | if (ty.isPtrAtRuntime()) return; |
| 8790 | 8911 | |
| 8791 | | return sema.mod.fail( |
| 8792 | | &block.base, |
| 8912 | return sema.fail( |
| 8913 | block, |
| 8793 | 8914 | ty_src, |
| 8794 | 8915 | "expected bool, integer, float, enum, or pointer type; found {}", |
| 8795 | 8916 | .{ty}, |
| ... | ... | @@ -8798,8 +8919,8 @@ fn checkAtomicOperandType( |
| 8798 | 8919 | }; |
| 8799 | 8920 | const bit_count = int_ty.intInfo(target).bits; |
| 8800 | 8921 | if (bit_count > max_atomic_bits) { |
| 8801 | | return sema.mod.fail( |
| 8802 | | &block.base, |
| 8922 | return sema.fail( |
| 8923 | block, |
| 8803 | 8924 | ty_src, |
| 8804 | 8925 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", |
| 8805 | 8926 | .{ max_atomic_bits, bit_count }, |
| ... | ... | @@ -8823,7 +8944,7 @@ fn resolveExportOptions( |
| 8823 | 8944 | const linkage_index = struct_obj.fields.getIndex("linkage").?; |
| 8824 | 8945 | const section_index = struct_obj.fields.getIndex("section").?; |
| 8825 | 8946 | if (!fields[section_index].isNull()) { |
| 8826 | | return sema.mod.fail(&block.base, src, "TODO: implement exporting with linksection", .{}); |
| 8947 | return sema.fail(block, src, "TODO: implement exporting with linksection", .{}); |
| 8827 | 8948 | } |
| 8828 | 8949 | return std.builtin.ExportOptions{ |
| 8829 | 8950 | .name = try fields[name_index].toAllocatedBytes(sema.arena), |
| ... | ... | @@ -8864,7 +8985,6 @@ fn zirCmpxchg( |
| 8864 | 8985 | inst: Zir.Inst.Index, |
| 8865 | 8986 | air_tag: Air.Inst.Tag, |
| 8866 | 8987 | ) CompileError!Air.Inst.Ref { |
| 8867 | | const mod = sema.mod; |
| 8868 | 8988 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8869 | 8989 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; |
| 8870 | 8990 | const src = inst_data.src(); |
| ... | ... | @@ -8880,8 +9000,8 @@ fn zirCmpxchg( |
| 8880 | 9000 | const elem_ty = sema.typeOf(ptr).elemType(); |
| 8881 | 9001 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); |
| 8882 | 9002 | if (elem_ty.zigTypeTag() == .Float) { |
| 8883 | | return mod.fail( |
| 8884 | | &block.base, |
| 9003 | return sema.fail( |
| 9004 | block, |
| 8885 | 9005 | elem_ty_src, |
| 8886 | 9006 | "expected bool, integer, enum, or pointer type; found '{}'", |
| 8887 | 9007 | .{elem_ty}, |
| ... | ... | @@ -8893,16 +9013,16 @@ fn zirCmpxchg( |
| 8893 | 9013 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); |
| 8894 | 9014 | |
| 8895 | 9015 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { |
| 8896 | | return mod.fail(&block.base, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| 9016 | return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{}); |
| 8897 | 9017 | } |
| 8898 | 9018 | if (@enumToInt(failure_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { |
| 8899 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{}); |
| 9019 | return sema.fail(block, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{}); |
| 8900 | 9020 | } |
| 8901 | 9021 | if (@enumToInt(failure_order) > @enumToInt(success_order)) { |
| 8902 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be no stricter than success", .{}); |
| 9022 | return sema.fail(block, failure_order_src, "failure atomic ordering must be no stricter than success", .{}); |
| 8903 | 9023 | } |
| 8904 | 9024 | if (failure_order == .Release or failure_order == .AcqRel) { |
| 8905 | | return mod.fail(&block.base, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{}); |
| 9025 | return sema.fail(block, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{}); |
| 8906 | 9026 | } |
| 8907 | 9027 | |
| 8908 | 9028 | const result_ty = try Module.optionalType(sema.arena, elem_ty); |
| ... | ... | @@ -8952,25 +9072,25 @@ fn zirCmpxchg( |
| 8952 | 9072 | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8953 | 9073 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8954 | 9074 | const src = inst_data.src(); |
| 8955 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{}); |
| 9075 | return sema.fail(block, src, "TODO: Sema.zirSplat", .{}); |
| 8956 | 9076 | } |
| 8957 | 9077 | |
| 8958 | 9078 | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8959 | 9079 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8960 | 9080 | const src = inst_data.src(); |
| 8961 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{}); |
| 9081 | return sema.fail(block, src, "TODO: Sema.zirReduce", .{}); |
| 8962 | 9082 | } |
| 8963 | 9083 | |
| 8964 | 9084 | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8965 | 9085 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8966 | 9086 | const src = inst_data.src(); |
| 8967 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{}); |
| 9087 | return sema.fail(block, src, "TODO: Sema.zirShuffle", .{}); |
| 8968 | 9088 | } |
| 8969 | 9089 | |
| 8970 | 9090 | fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8971 | 9091 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8972 | 9092 | const src = inst_data.src(); |
| 8973 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirSelect", .{}); |
| 9093 | return sema.fail(block, src, "TODO: Sema.zirSelect", .{}); |
| 8974 | 9094 | } |
| 8975 | 9095 | |
| 8976 | 9096 | fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8988,8 +9108,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 8988 | 9108 | |
| 8989 | 9109 | switch (order) { |
| 8990 | 9110 | .Release, .AcqRel => { |
| 8991 | | return sema.mod.fail( |
| 8992 | | &block.base, |
| 9111 | return sema.fail( |
| 9112 | block, |
| 8993 | 9113 | order_src, |
| 8994 | 9114 | "@atomicLoad atomic ordering must not be Release or AcqRel", |
| 8995 | 9115 | .{}, |
| ... | ... | @@ -9019,7 +9139,6 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 9019 | 9139 | } |
| 9020 | 9140 | |
| 9021 | 9141 | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9022 | | const mod = sema.mod; |
| 9023 | 9142 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9024 | 9143 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 9025 | 9144 | const src = inst_data.src(); |
| ... | ... | @@ -9037,14 +9156,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9037 | 9156 | |
| 9038 | 9157 | switch (operand_ty.zigTypeTag()) { |
| 9039 | 9158 | .Enum => if (op != .Xchg) { |
| 9040 | | return mod.fail(&block.base, op_src, "@atomicRmw with enum only allowed with .Xchg", .{}); |
| 9159 | return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{}); |
| 9041 | 9160 | }, |
| 9042 | 9161 | .Bool => if (op != .Xchg) { |
| 9043 | | return mod.fail(&block.base, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); |
| 9162 | return sema.fail(block, op_src, "@atomicRmw with bool only allowed with .Xchg", .{}); |
| 9044 | 9163 | }, |
| 9045 | 9164 | .Float => switch (op) { |
| 9046 | 9165 | .Xchg, .Add, .Sub => {}, |
| 9047 | | else => return mod.fail(&block.base, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}), |
| 9166 | else => return sema.fail(block, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}), |
| 9048 | 9167 | }, |
| 9049 | 9168 | else => {}, |
| 9050 | 9169 | } |
| ... | ... | @@ -9052,7 +9171,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9052 | 9171 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); |
| 9053 | 9172 | |
| 9054 | 9173 | if (order == .Unordered) { |
| 9055 | | return mod.fail(&block.base, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| 9174 | return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{}); |
| 9056 | 9175 | } |
| 9057 | 9176 | |
| 9058 | 9177 | // special case zero bit types |
| ... | ... | @@ -9115,8 +9234,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9115 | 9234 | |
| 9116 | 9235 | const air_tag: Air.Inst.Tag = switch (order) { |
| 9117 | 9236 | .Acquire, .AcqRel => { |
| 9118 | | return sema.mod.fail( |
| 9119 | | &block.base, |
| 9237 | return sema.fail( |
| 9238 | block, |
| 9120 | 9239 | order_src, |
| 9121 | 9240 | "@atomicStore atomic ordering must not be Acquire or AcqRel", |
| 9122 | 9241 | .{}, |
| ... | ... | @@ -9134,31 +9253,31 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9134 | 9253 | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9135 | 9254 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9136 | 9255 | const src = inst_data.src(); |
| 9137 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{}); |
| 9256 | return sema.fail(block, src, "TODO: Sema.zirMulAdd", .{}); |
| 9138 | 9257 | } |
| 9139 | 9258 | |
| 9140 | 9259 | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9141 | 9260 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9142 | 9261 | const src = inst_data.src(); |
| 9143 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{}); |
| 9262 | return sema.fail(block, src, "TODO: Sema.zirBuiltinCall", .{}); |
| 9144 | 9263 | } |
| 9145 | 9264 | |
| 9146 | 9265 | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9147 | 9266 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9148 | 9267 | const src = inst_data.src(); |
| 9149 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{}); |
| 9268 | return sema.fail(block, src, "TODO: Sema.zirFieldPtrType", .{}); |
| 9150 | 9269 | } |
| 9151 | 9270 | |
| 9152 | 9271 | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9153 | 9272 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9154 | 9273 | const src = inst_data.src(); |
| 9155 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{}); |
| 9274 | return sema.fail(block, src, "TODO: Sema.zirFieldParentPtr", .{}); |
| 9156 | 9275 | } |
| 9157 | 9276 | |
| 9158 | 9277 | fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9159 | 9278 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9160 | 9279 | const src = inst_data.src(); |
| 9161 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMaximum", .{}); |
| 9280 | return sema.fail(block, src, "TODO: Sema.zirMaximum", .{}); |
| 9162 | 9281 | } |
| 9163 | 9282 | |
| 9164 | 9283 | fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | ... | @@ -9172,16 +9291,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9172 | 9291 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9173 | 9292 | |
| 9174 | 9293 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { |
| 9175 | | return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9294 | return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9176 | 9295 | } |
| 9177 | 9296 | if (dest_ptr_ty.isConstPtr()) { |
| 9178 | | return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9297 | return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9179 | 9298 | } |
| 9180 | 9299 | |
| 9181 | 9300 | const uncasted_src_ptr = sema.resolveInst(extra.source); |
| 9182 | 9301 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); |
| 9183 | 9302 | if (uncasted_src_ptr_ty.zigTypeTag() != .Pointer) { |
| 9184 | | return sema.mod.fail(&block.base, src_src, "expected pointer, found '{}'", .{ |
| 9303 | return sema.fail(block, src_src, "expected pointer, found '{}'", .{ |
| 9185 | 9304 | uncasted_src_ptr_ty, |
| 9186 | 9305 | }); |
| 9187 | 9306 | } |
| ... | ... | @@ -9208,7 +9327,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9208 | 9327 | _ = dest_ptr_val; |
| 9209 | 9328 | _ = src_ptr_val; |
| 9210 | 9329 | _ = len_val; |
| 9211 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy at comptime", .{}); |
| 9330 | return sema.fail(block, src, "TODO: Sema.zirMemcpy at comptime", .{}); |
| 9212 | 9331 | } else break :rs len_src; |
| 9213 | 9332 | } else break :rs src_src; |
| 9214 | 9333 | } else dest_src; |
| ... | ... | @@ -9236,10 +9355,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9236 | 9355 | const dest_ptr = sema.resolveInst(extra.dest); |
| 9237 | 9356 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9238 | 9357 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { |
| 9239 | | return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9358 | return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty}); |
| 9240 | 9359 | } |
| 9241 | 9360 | if (dest_ptr_ty.isConstPtr()) { |
| 9242 | | return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9361 | return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty}); |
| 9243 | 9362 | } |
| 9244 | 9363 | const elem_ty = dest_ptr_ty.elemType2(); |
| 9245 | 9364 | const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src); |
| ... | ... | @@ -9254,7 +9373,7 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9254 | 9373 | _ = ptr_val; |
| 9255 | 9374 | _ = len_val; |
| 9256 | 9375 | _ = val; |
| 9257 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset at comptime", .{}); |
| 9376 | return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{}); |
| 9258 | 9377 | } else break :rs value_src; |
| 9259 | 9378 | } else break :rs len_src; |
| 9260 | 9379 | } else dest_src; |
| ... | ... | @@ -9275,19 +9394,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9275 | 9394 | fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9276 | 9395 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9277 | 9396 | const src = inst_data.src(); |
| 9278 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirMinimum", .{}); |
| 9397 | return sema.fail(block, src, "TODO: Sema.zirMinimum", .{}); |
| 9279 | 9398 | } |
| 9280 | 9399 | |
| 9281 | 9400 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9282 | 9401 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9283 | 9402 | const src = inst_data.src(); |
| 9284 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 9403 | return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{}); |
| 9285 | 9404 | } |
| 9286 | 9405 | |
| 9287 | 9406 | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9288 | 9407 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9289 | 9408 | const src = inst_data.src(); |
| 9290 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{}); |
| 9409 | return sema.fail(block, src, "TODO: Sema.zirResume", .{}); |
| 9291 | 9410 | } |
| 9292 | 9411 | |
| 9293 | 9412 | fn zirAwait( |
| ... | ... | @@ -9300,7 +9419,7 @@ fn zirAwait( |
| 9300 | 9419 | const src = inst_data.src(); |
| 9301 | 9420 | |
| 9302 | 9421 | _ = is_nosuspend; |
| 9303 | | return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{}); |
| 9422 | return sema.fail(block, src, "TODO: Sema.zirAwait", .{}); |
| 9304 | 9423 | } |
| 9305 | 9424 | |
| 9306 | 9425 | fn zirVarExtended( |
| ... | ... | @@ -9360,7 +9479,7 @@ fn zirVarExtended( |
| 9360 | 9479 | if (lib_name != null) { |
| 9361 | 9480 | // Look at the sema code for functions which has this logic, it just needs to |
| 9362 | 9481 | // be extracted and shared by both var and func |
| 9363 | | return sema.mod.fail(&block.base, src, "TODO: handle var with lib_name in Sema", .{}); |
| 9482 | return sema.fail(block, src, "TODO: handle var with lib_name in Sema", .{}); |
| 9364 | 9483 | } |
| 9365 | 9484 | |
| 9366 | 9485 | const new_var = try sema.gpa.create(Module.Var); |
| ... | ... | @@ -9496,7 +9615,7 @@ fn zirWasmMemorySize( |
| 9496 | 9615 | ) CompileError!Air.Inst.Ref { |
| 9497 | 9616 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 9498 | 9617 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9499 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{}); |
| 9618 | return sema.fail(block, src, "TODO: implement Sema.zirWasmMemorySize", .{}); |
| 9500 | 9619 | } |
| 9501 | 9620 | |
| 9502 | 9621 | fn zirWasmMemoryGrow( |
| ... | ... | @@ -9506,7 +9625,7 @@ fn zirWasmMemoryGrow( |
| 9506 | 9625 | ) CompileError!Air.Inst.Ref { |
| 9507 | 9626 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9508 | 9627 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9509 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 9628 | return sema.fail(block, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 9510 | 9629 | } |
| 9511 | 9630 | |
| 9512 | 9631 | fn zirBuiltinExtern( |
| ... | ... | @@ -9516,12 +9635,12 @@ fn zirBuiltinExtern( |
| 9516 | 9635 | ) CompileError!Air.Inst.Ref { |
| 9517 | 9636 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9518 | 9637 | const src: LazySrcLoc = .{ .node_offset = extra.node }; |
| 9519 | | return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{}); |
| 9638 | return sema.fail(block, src, "TODO: implement Sema.zirBuiltinExtern", .{}); |
| 9520 | 9639 | } |
| 9521 | 9640 | |
| 9522 | 9641 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9523 | 9642 | if (sema.func == null) { |
| 9524 | | return sema.mod.fail(&block.base, src, "instruction illegal outside function body", .{}); |
| 9643 | return sema.fail(block, src, "instruction illegal outside function body", .{}); |
| 9525 | 9644 | } |
| 9526 | 9645 | } |
| 9527 | 9646 | |
| ... | ... | @@ -9579,7 +9698,7 @@ fn validateVarType( |
| 9579 | 9698 | }, |
| 9580 | 9699 | } else unreachable; // TODO should not need else unreachable |
| 9581 | 9700 | if (!ok) { |
| 9582 | | return sema.mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{var_ty}); |
| 9701 | return sema.fail(block, src, "variable of type '{}' must be const or comptime", .{var_ty}); |
| 9583 | 9702 | } |
| 9584 | 9703 | } |
| 9585 | 9704 | |
| ... | ... | @@ -9684,7 +9803,7 @@ fn panicWithMsg( |
| 9684 | 9803 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 9685 | 9804 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ |
| 9686 | 9805 | .pointee_type = stack_trace_ty, |
| 9687 | | .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic |
| 9806 | .@"addrspace" = target_util.defaultAddressSpace(mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic |
| 9688 | 9807 | }); |
| 9689 | 9808 | const null_stack_trace = try sema.addConstant( |
| 9690 | 9809 | try Module.optionalType(arena, ptr_stack_trace_ty), |
| ... | ... | @@ -9730,7 +9849,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9730 | 9849 | sema.branch_count += 1; |
| 9731 | 9850 | if (sema.branch_count > sema.branch_quota) { |
| 9732 | 9851 | // TODO show the "called from here" stack |
| 9733 | | return sema.mod.fail(&block.base, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota}); |
| 9852 | return sema.fail(block, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota}); |
| 9734 | 9853 | } |
| 9735 | 9854 | } |
| 9736 | 9855 | |
| ... | ... | @@ -9745,7 +9864,6 @@ fn fieldVal( |
| 9745 | 9864 | // When editing this function, note that there is corresponding logic to be edited |
| 9746 | 9865 | // in `fieldPtr`. This function takes a value and returns a value. |
| 9747 | 9866 | |
| 9748 | | const mod = sema.mod; |
| 9749 | 9867 | const arena = sema.arena; |
| 9750 | 9868 | const object_src = src; // TODO better source location |
| 9751 | 9869 | const object_ty = sema.typeOf(object); |
| ... | ... | @@ -9758,8 +9876,8 @@ fn fieldVal( |
| 9758 | 9876 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), |
| 9759 | 9877 | ); |
| 9760 | 9878 | } else { |
| 9761 | | return mod.fail( |
| 9762 | | &block.base, |
| 9879 | return sema.fail( |
| 9880 | block, |
| 9763 | 9881 | field_name_src, |
| 9764 | 9882 | "no member named '{s}' in '{}'", |
| 9765 | 9883 | .{ field_name, object_ty }, |
| ... | ... | @@ -9773,8 +9891,8 @@ fn fieldVal( |
| 9773 | 9891 | const result_ty = object_ty.slicePtrFieldType(buf); |
| 9774 | 9892 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { |
| 9775 | 9893 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 9776 | | return mod.fail( |
| 9777 | | &block.base, |
| 9894 | return sema.fail( |
| 9895 | block, |
| 9778 | 9896 | field_name_src, |
| 9779 | 9897 | "TODO implement comptime slice ptr", |
| 9780 | 9898 | .{}, |
| ... | ... | @@ -9794,8 +9912,8 @@ fn fieldVal( |
| 9794 | 9912 | try sema.requireRuntimeBlock(block, src); |
| 9795 | 9913 | return block.addTyOp(.slice_len, result_ty, object); |
| 9796 | 9914 | } else { |
| 9797 | | return mod.fail( |
| 9798 | | &block.base, |
| 9915 | return sema.fail( |
| 9916 | block, |
| 9799 | 9917 | field_name_src, |
| 9800 | 9918 | "no member named '{s}' in '{}'", |
| 9801 | 9919 | .{ field_name, object_ty }, |
| ... | ... | @@ -9812,8 +9930,8 @@ fn fieldVal( |
| 9812 | 9930 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), |
| 9813 | 9931 | ); |
| 9814 | 9932 | } else { |
| 9815 | | return mod.fail( |
| 9816 | | &block.base, |
| 9933 | return sema.fail( |
| 9934 | block, |
| 9817 | 9935 | field_name_src, |
| 9818 | 9936 | "no member named '{s}' in '{}'", |
| 9819 | 9937 | .{ field_name, object_ty }, |
| ... | ... | @@ -9850,10 +9968,10 @@ fn fieldVal( |
| 9850 | 9968 | break :blk name; |
| 9851 | 9969 | } |
| 9852 | 9970 | } |
| 9853 | | return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{ |
| 9971 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 9854 | 9972 | field_name, child_type, |
| 9855 | 9973 | }); |
| 9856 | | } else (try mod.getErrorValue(field_name)).key; |
| 9974 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 9857 | 9975 | |
| 9858 | 9976 | return sema.addConstant( |
| 9859 | 9977 | try child_type.copy(arena), |
| ... | ... | @@ -9873,7 +9991,7 @@ fn fieldVal( |
| 9873 | 9991 | .Union => "union", |
| 9874 | 9992 | else => unreachable, |
| 9875 | 9993 | }; |
| 9876 | | return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{ |
| 9994 | return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{ |
| 9877 | 9995 | kw_name, child_type, field_name, |
| 9878 | 9996 | }); |
| 9879 | 9997 | }, |
| ... | ... | @@ -9885,14 +10003,14 @@ fn fieldVal( |
| 9885 | 10003 | } |
| 9886 | 10004 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 9887 | 10005 | const msg = msg: { |
| 9888 | | const msg = try mod.errMsg( |
| 9889 | | &block.base, |
| 10006 | const msg = try sema.errMsg( |
| 10007 | block, |
| 9890 | 10008 | src, |
| 9891 | 10009 | "enum '{}' has no member named '{s}'", |
| 9892 | 10010 | .{ child_type, field_name }, |
| 9893 | 10011 | ); |
| 9894 | 10012 | errdefer msg.destroy(sema.gpa); |
| 9895 | | try mod.errNoteNonLazy( |
| 10013 | try sema.mod.errNoteNonLazy( |
| 9896 | 10014 | child_type.declSrcLoc(), |
| 9897 | 10015 | msg, |
| 9898 | 10016 | "enum declared here", |
| ... | ... | @@ -9900,20 +10018,20 @@ fn fieldVal( |
| 9900 | 10018 | ); |
| 9901 | 10019 | break :msg msg; |
| 9902 | 10020 | }; |
| 9903 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10021 | return sema.failWithOwnedErrorMsg(msg); |
| 9904 | 10022 | }; |
| 9905 | 10023 | const field_index_u32 = @intCast(u32, field_index); |
| 9906 | 10024 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); |
| 9907 | 10025 | return sema.addConstant(try child_type.copy(arena), enum_val); |
| 9908 | 10026 | }, |
| 9909 | | else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}), |
| 10027 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type}), |
| 9910 | 10028 | } |
| 9911 | 10029 | }, |
| 9912 | 10030 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9913 | 10031 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9914 | 10032 | else => {}, |
| 9915 | 10033 | } |
| 9916 | | return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty}); |
| 10034 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); |
| 9917 | 10035 | } |
| 9918 | 10036 | |
| 9919 | 10037 | fn fieldPtr( |
| ... | ... | @@ -9927,12 +10045,11 @@ fn fieldPtr( |
| 9927 | 10045 | // When editing this function, note that there is corresponding logic to be edited |
| 9928 | 10046 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 9929 | 10047 | |
| 9930 | | const mod = sema.mod; |
| 9931 | 10048 | const object_ptr_src = src; // TODO better source location |
| 9932 | 10049 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 9933 | 10050 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { |
| 9934 | 10051 | .Pointer => object_ptr_ty.elemType(), |
| 9935 | | else => return mod.fail(&block.base, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}), |
| 10052 | else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}), |
| 9936 | 10053 | }; |
| 9937 | 10054 | switch (object_ty.zigTypeTag()) { |
| 9938 | 10055 | .Array => { |
| ... | ... | @@ -9944,8 +10061,8 @@ fn fieldPtr( |
| 9944 | 10061 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), |
| 9945 | 10062 | )); |
| 9946 | 10063 | } else { |
| 9947 | | return mod.fail( |
| 9948 | | &block.base, |
| 10064 | return sema.fail( |
| 10065 | block, |
| 9949 | 10066 | field_name_src, |
| 9950 | 10067 | "no member named '{s}' in '{}'", |
| 9951 | 10068 | .{ field_name, object_ty }, |
| ... | ... | @@ -9962,22 +10079,22 @@ fn fieldPtr( |
| 9962 | 10079 | // the runtime value to it, and then return the `alloc`. |
| 9963 | 10080 | // In both cases the pointer should be const. |
| 9964 | 10081 | if (mem.eql(u8, field_name, "ptr")) { |
| 9965 | | return mod.fail( |
| 9966 | | &block.base, |
| 10082 | return sema.fail( |
| 10083 | block, |
| 9967 | 10084 | field_name_src, |
| 9968 | 10085 | "TODO: implement reference to 'ptr' field of slice '{}'", |
| 9969 | 10086 | .{object_ty}, |
| 9970 | 10087 | ); |
| 9971 | 10088 | } else if (mem.eql(u8, field_name, "len")) { |
| 9972 | | return mod.fail( |
| 9973 | | &block.base, |
| 10089 | return sema.fail( |
| 10090 | block, |
| 9974 | 10091 | field_name_src, |
| 9975 | 10092 | "TODO: implement reference to 'len' field of slice '{}'", |
| 9976 | 10093 | .{object_ty}, |
| 9977 | 10094 | ); |
| 9978 | 10095 | } else { |
| 9979 | | return mod.fail( |
| 9980 | | &block.base, |
| 10096 | return sema.fail( |
| 10097 | block, |
| 9981 | 10098 | field_name_src, |
| 9982 | 10099 | "no member named '{s}' in '{}'", |
| 9983 | 10100 | .{ field_name, object_ty }, |
| ... | ... | @@ -9996,8 +10113,8 @@ fn fieldPtr( |
| 9996 | 10113 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), |
| 9997 | 10114 | )); |
| 9998 | 10115 | } else { |
| 9999 | | return mod.fail( |
| 10000 | | &block.base, |
| 10116 | return sema.fail( |
| 10117 | block, |
| 10001 | 10118 | field_name_src, |
| 10002 | 10119 | "no member named '{s}' in '{}'", |
| 10003 | 10120 | .{ field_name, object_ty }, |
| ... | ... | @@ -10036,10 +10153,10 @@ fn fieldPtr( |
| 10036 | 10153 | break :blk name; |
| 10037 | 10154 | } |
| 10038 | 10155 | } |
| 10039 | | return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{ |
| 10156 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ |
| 10040 | 10157 | field_name, child_type, |
| 10041 | 10158 | }); |
| 10042 | | } else (try mod.getErrorValue(field_name)).key; |
| 10159 | } else (try sema.mod.getErrorValue(field_name)).key; |
| 10043 | 10160 | |
| 10044 | 10161 | var anon_decl = try block.startAnonDecl(); |
| 10045 | 10162 | defer anon_decl.deinit(); |
| ... | ... | @@ -10061,7 +10178,7 @@ fn fieldPtr( |
| 10061 | 10178 | .Union => "union", |
| 10062 | 10179 | else => unreachable, |
| 10063 | 10180 | }; |
| 10064 | | return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{ |
| 10181 | return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{ |
| 10065 | 10182 | kw_name, child_type, field_name, |
| 10066 | 10183 | }); |
| 10067 | 10184 | }, |
| ... | ... | @@ -10073,14 +10190,14 @@ fn fieldPtr( |
| 10073 | 10190 | } |
| 10074 | 10191 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 10075 | 10192 | const msg = msg: { |
| 10076 | | const msg = try mod.errMsg( |
| 10077 | | &block.base, |
| 10193 | const msg = try sema.errMsg( |
| 10194 | block, |
| 10078 | 10195 | src, |
| 10079 | 10196 | "enum '{}' has no member named '{s}'", |
| 10080 | 10197 | .{ child_type, field_name }, |
| 10081 | 10198 | ); |
| 10082 | 10199 | errdefer msg.destroy(sema.gpa); |
| 10083 | | try mod.errNoteNonLazy( |
| 10200 | try sema.mod.errNoteNonLazy( |
| 10084 | 10201 | child_type.declSrcLoc(), |
| 10085 | 10202 | msg, |
| 10086 | 10203 | "enum declared here", |
| ... | ... | @@ -10088,7 +10205,7 @@ fn fieldPtr( |
| 10088 | 10205 | ); |
| 10089 | 10206 | break :msg msg; |
| 10090 | 10207 | }; |
| 10091 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10208 | return sema.failWithOwnedErrorMsg(msg); |
| 10092 | 10209 | }; |
| 10093 | 10210 | const field_index_u32 = @intCast(u32, field_index); |
| 10094 | 10211 | var anon_decl = try block.startAnonDecl(); |
| ... | ... | @@ -10098,14 +10215,14 @@ fn fieldPtr( |
| 10098 | 10215 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), |
| 10099 | 10216 | )); |
| 10100 | 10217 | }, |
| 10101 | | else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}), |
| 10218 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type}), |
| 10102 | 10219 | } |
| 10103 | 10220 | }, |
| 10104 | 10221 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10105 | 10222 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10106 | 10223 | else => {}, |
| 10107 | 10224 | } |
| 10108 | | return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty}); |
| 10225 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty}); |
| 10109 | 10226 | } |
| 10110 | 10227 | |
| 10111 | 10228 | fn fieldCallBind( |
| ... | ... | @@ -10119,13 +10236,12 @@ fn fieldCallBind( |
| 10119 | 10236 | // When editing this function, note that there is corresponding logic to be edited |
| 10120 | 10237 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 10121 | 10238 | |
| 10122 | | const mod = sema.mod; |
| 10123 | 10239 | const raw_ptr_src = src; // TODO better source location |
| 10124 | 10240 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 10125 | 10241 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) |
| 10126 | 10242 | raw_ptr_ty.childType() |
| 10127 | 10243 | else |
| 10128 | | return mod.fail(&block.base, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty}); |
| 10244 | return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty}); |
| 10129 | 10245 | |
| 10130 | 10246 | // Optionally dereference a second pointer to get the concrete type. |
| 10131 | 10247 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; |
| ... | ... | @@ -10194,7 +10310,7 @@ fn fieldCallBind( |
| 10194 | 10310 | }; |
| 10195 | 10311 | return sema.analyzeLoad(block, src, ptr_inst, src); |
| 10196 | 10312 | }, |
| 10197 | | .Union => return sema.mod.fail(&block.base, src, "TODO implement field calls on unions", .{}), |
| 10313 | .Union => return sema.fail(block, src, "TODO implement field calls on unions", .{}), |
| 10198 | 10314 | .Type => { |
| 10199 | 10315 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| 10200 | 10316 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); |
| ... | ... | @@ -10247,7 +10363,7 @@ fn fieldCallBind( |
| 10247 | 10363 | else => {}, |
| 10248 | 10364 | } |
| 10249 | 10365 | |
| 10250 | | return mod.fail(&block.base, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); |
| 10366 | return sema.fail(block, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name }); |
| 10251 | 10367 | } |
| 10252 | 10368 | |
| 10253 | 10369 | fn namespaceLookup( |
| ... | ... | @@ -10257,19 +10373,18 @@ fn namespaceLookup( |
| 10257 | 10373 | namespace: *Scope.Namespace, |
| 10258 | 10374 | decl_name: []const u8, |
| 10259 | 10375 | ) CompileError!?*Decl { |
| 10260 | | const mod = sema.mod; |
| 10261 | 10376 | const gpa = sema.gpa; |
| 10262 | 10377 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { |
| 10263 | 10378 | if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) { |
| 10264 | 10379 | const msg = msg: { |
| 10265 | | const msg = try mod.errMsg(&block.base, src, "'{s}' is not marked 'pub'", .{ |
| 10380 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ |
| 10266 | 10381 | decl_name, |
| 10267 | 10382 | }); |
| 10268 | 10383 | errdefer msg.destroy(gpa); |
| 10269 | | try mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); |
| 10384 | try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); |
| 10270 | 10385 | break :msg msg; |
| 10271 | 10386 | }; |
| 10272 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10387 | return sema.failWithOwnedErrorMsg(msg); |
| 10273 | 10388 | } |
| 10274 | 10389 | return decl; |
| 10275 | 10390 | } |
| ... | ... | @@ -10435,7 +10550,7 @@ fn unionFieldVal( |
| 10435 | 10550 | } |
| 10436 | 10551 | |
| 10437 | 10552 | try sema.requireRuntimeBlock(block, src); |
| 10438 | | return sema.mod.fail(&block.base, src, "TODO implement runtime union field access", .{}); |
| 10553 | return sema.fail(block, src, "TODO implement runtime union field access", .{}); |
| 10439 | 10554 | } |
| 10440 | 10555 | |
| 10441 | 10556 | fn elemPtr( |
| ... | ... | @@ -10450,10 +10565,10 @@ fn elemPtr( |
| 10450 | 10565 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 10451 | 10566 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { |
| 10452 | 10567 | .Pointer => array_ptr_ty.elemType(), |
| 10453 | | else => return sema.mod.fail(&block.base, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 10568 | else => return sema.fail(block, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 10454 | 10569 | }; |
| 10455 | 10570 | if (!array_ty.isIndexable()) { |
| 10456 | | return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty}); |
| 10571 | return sema.fail(block, src, "array access of non-array type '{}'", .{array_ty}); |
| 10457 | 10572 | } |
| 10458 | 10573 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { |
| 10459 | 10574 | // we have to deref the ptr operand to get the actual array pointer |
| ... | ... | @@ -10464,7 +10579,7 @@ fn elemPtr( |
| 10464 | 10579 | return sema.elemPtrArray(block, src, array_ptr, elem_index, elem_index_src); |
| 10465 | 10580 | } |
| 10466 | 10581 | |
| 10467 | | return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr", .{}); |
| 10582 | return sema.fail(block, src, "TODO implement more analyze elemptr", .{}); |
| 10468 | 10583 | } |
| 10469 | 10584 | |
| 10470 | 10585 | fn elemVal( |
| ... | ... | @@ -10482,7 +10597,7 @@ fn elemVal( |
| 10482 | 10597 | .Slice => { |
| 10483 | 10598 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { |
| 10484 | 10599 | _ = slice_val; |
| 10485 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10600 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10486 | 10601 | } |
| 10487 | 10602 | try sema.requireRuntimeBlock(block, src); |
| 10488 | 10603 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); |
| ... | ... | @@ -10490,7 +10605,7 @@ fn elemVal( |
| 10490 | 10605 | .Many, .C => { |
| 10491 | 10606 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { |
| 10492 | 10607 | _ = ptr_val; |
| 10493 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10608 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10494 | 10609 | } |
| 10495 | 10610 | try sema.requireRuntimeBlock(block, src); |
| 10496 | 10611 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); |
| ... | ... | @@ -10505,7 +10620,7 @@ fn elemVal( |
| 10505 | 10620 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10506 | 10621 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { |
| 10507 | 10622 | _ = slice_val; |
| 10508 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10623 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{}); |
| 10509 | 10624 | } |
| 10510 | 10625 | try sema.requireRuntimeBlock(block, src); |
| 10511 | 10626 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| ... | ... | @@ -10519,7 +10634,7 @@ fn elemVal( |
| 10519 | 10634 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10520 | 10635 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { |
| 10521 | 10636 | _ = ptr_val; |
| 10522 | | return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10637 | return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{}); |
| 10523 | 10638 | } |
| 10524 | 10639 | try sema.requireRuntimeBlock(block, src); |
| 10525 | 10640 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); |
| ... | ... | @@ -10527,8 +10642,8 @@ fn elemVal( |
| 10527 | 10642 | try sema.requireRuntimeBlock(block, src); |
| 10528 | 10643 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); |
| 10529 | 10644 | }, |
| 10530 | | .One => return sema.mod.fail( |
| 10531 | | &block.base, |
| 10645 | .One => return sema.fail( |
| 10646 | block, |
| 10532 | 10647 | array_ptr_src, |
| 10533 | 10648 | "expected pointer, found '{}'", |
| 10534 | 10649 | .{indexable_ty.elemType()}, |
| ... | ... | @@ -10538,8 +10653,8 @@ fn elemVal( |
| 10538 | 10653 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); |
| 10539 | 10654 | return sema.analyzeLoad(block, src, ptr, elem_index_src); |
| 10540 | 10655 | }, |
| 10541 | | else => return sema.mod.fail( |
| 10542 | | &block.base, |
| 10656 | else => return sema.fail( |
| 10657 | block, |
| 10543 | 10658 | array_ptr_src, |
| 10544 | 10659 | "expected pointer, found '{}'", |
| 10545 | 10660 | .{indexable_ty}, |
| ... | ... | @@ -10547,8 +10662,8 @@ fn elemVal( |
| 10547 | 10662 | } |
| 10548 | 10663 | }, |
| 10549 | 10664 | }, |
| 10550 | | else => return sema.mod.fail( |
| 10551 | | &block.base, |
| 10665 | else => return sema.fail( |
| 10666 | block, |
| 10552 | 10667 | array_ptr_src, |
| 10553 | 10668 | "expected pointer, found '{}'", |
| 10554 | 10669 | .{maybe_ptr_ty}, |
| ... | ... | @@ -10616,10 +10731,10 @@ fn coerce( |
| 10616 | 10731 | if (dest_type.eql(inst_ty)) |
| 10617 | 10732 | return inst; |
| 10618 | 10733 | |
| 10619 | | const mod = sema.mod; |
| 10620 | 10734 | const arena = sema.arena; |
| 10735 | const target = sema.mod.getTarget(); |
| 10621 | 10736 | |
| 10622 | | const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, mod.getTarget()); |
| 10737 | const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, target); |
| 10623 | 10738 | if (in_memory_result == .ok) { |
| 10624 | 10739 | return sema.bitcast(block, dest_type, inst, inst_src); |
| 10625 | 10740 | } |
| ... | ... | @@ -10636,8 +10751,6 @@ fn coerce( |
| 10636 | 10751 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| |
| 10637 | 10752 | return some; |
| 10638 | 10753 | |
| 10639 | | const target = mod.getTarget(); |
| 10640 | | |
| 10641 | 10754 | switch (dest_type.zigTypeTag()) { |
| 10642 | 10755 | .Optional => { |
| 10643 | 10756 | // null to ?T |
| ... | ... | @@ -10664,7 +10777,7 @@ fn coerce( |
| 10664 | 10777 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; |
| 10665 | 10778 | |
| 10666 | 10779 | const dst_elem_type = dest_type.elemType(); |
| 10667 | | switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, mod.getTarget())) { |
| 10780 | switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, target)) { |
| 10668 | 10781 | .ok => {}, |
| 10669 | 10782 | .no_match => break :src_array_ptr, |
| 10670 | 10783 | } |
| ... | ... | @@ -10733,14 +10846,14 @@ fn coerce( |
| 10733 | 10846 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); |
| 10734 | 10847 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { |
| 10735 | 10848 | const msg = msg: { |
| 10736 | | const msg = try mod.errMsg( |
| 10737 | | &block.base, |
| 10849 | const msg = try sema.errMsg( |
| 10850 | block, |
| 10738 | 10851 | inst_src, |
| 10739 | 10852 | "enum '{}' has no field named '{s}'", |
| 10740 | 10853 | .{ resolved_dest_type, bytes }, |
| 10741 | 10854 | ); |
| 10742 | 10855 | errdefer msg.destroy(sema.gpa); |
| 10743 | | try mod.errNoteNonLazy( |
| 10856 | try sema.mod.errNoteNonLazy( |
| 10744 | 10857 | resolved_dest_type.declSrcLoc(), |
| 10745 | 10858 | msg, |
| 10746 | 10859 | "enum declared here", |
| ... | ... | @@ -10748,7 +10861,7 @@ fn coerce( |
| 10748 | 10861 | ); |
| 10749 | 10862 | break :msg msg; |
| 10750 | 10863 | }; |
| 10751 | | return mod.failWithOwnedErrorMsg(&block.base, msg); |
| 10864 | return sema.failWithOwnedErrorMsg(msg); |
| 10752 | 10865 | }; |
| 10753 | 10866 | return sema.addConstant( |
| 10754 | 10867 | resolved_dest_type, |
| ... | ... | @@ -10771,7 +10884,7 @@ fn coerce( |
| 10771 | 10884 | else => {}, |
| 10772 | 10885 | } |
| 10773 | 10886 | |
| 10774 | | return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst_ty }); |
| 10887 | return sema.fail(block, inst_src, "expected {}, found {}", .{ dest_type, inst_ty }); |
| 10775 | 10888 | } |
| 10776 | 10889 | |
| 10777 | 10890 | const InMemoryCoercionResult = enum { |
| ... | ... | @@ -10888,13 +11001,13 @@ fn coerceNum( |
| 10888 | 11001 | .ComptimeInt, .Int => switch (src_zig_tag) { |
| 10889 | 11002 | .Float, .ComptimeFloat => { |
| 10890 | 11003 | if (val.floatHasFraction()) { |
| 10891 | | return sema.mod.fail(&block.base, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type }); |
| 11004 | return sema.fail(block, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type }); |
| 10892 | 11005 | } |
| 10893 | | return sema.mod.fail(&block.base, inst_src, "TODO float to int", .{}); |
| 11006 | return sema.fail(block, inst_src, "TODO float to int", .{}); |
| 10894 | 11007 | }, |
| 10895 | 11008 | .Int, .ComptimeInt => { |
| 10896 | 11009 | if (!val.intFitsInType(dest_type, target)) { |
| 10897 | | return sema.mod.fail(&block.base, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val }); |
| 11010 | return sema.fail(block, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val }); |
| 10898 | 11011 | } |
| 10899 | 11012 | return try sema.addConstant(dest_type, val); |
| 10900 | 11013 | }, |
| ... | ... | @@ -10908,8 +11021,8 @@ fn coerceNum( |
| 10908 | 11021 | .Float => { |
| 10909 | 11022 | const result_val = try val.floatCast(sema.arena, dest_type); |
| 10910 | 11023 | if (!val.eql(result_val, dest_type)) { |
| 10911 | | return sema.mod.fail( |
| 10912 | | &block.base, |
| 11024 | return sema.fail( |
| 11025 | block, |
| 10913 | 11026 | inst_src, |
| 10914 | 11027 | "type {} cannot represent float value {}", |
| 10915 | 11028 | .{ dest_type, val }, |
| ... | ... | @@ -10922,8 +11035,8 @@ fn coerceNum( |
| 10922 | 11035 | // TODO implement this compile error |
| 10923 | 11036 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 10924 | 11037 | //if (!int_again_val.eql(val, inst_ty)) { |
| 10925 | | // return sema.mod.fail( |
| 10926 | | // &block.base, |
| 11038 | // return sema.fail( |
| 11039 | // block, |
| 10927 | 11040 | // inst_src, |
| 10928 | 11041 | // "type {} cannot represent integer value {}", |
| 10929 | 11042 | // .{ dest_type, val }, |
| ... | ... | @@ -10946,7 +11059,7 @@ fn coerceVarArgParam( |
| 10946 | 11059 | ) !Air.Inst.Ref { |
| 10947 | 11060 | const inst_ty = sema.typeOf(inst); |
| 10948 | 11061 | switch (inst_ty.zigTypeTag()) { |
| 10949 | | .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 11062 | .ComptimeInt, .ComptimeFloat => return sema.fail(block, inst_src, "integer and float literals in var args function must be casted", .{}), |
| 10950 | 11063 | else => {}, |
| 10951 | 11064 | } |
| 10952 | 11065 | // TODO implement more of this function. |
| ... | ... | @@ -10960,7 +11073,7 @@ fn storePtr( |
| 10960 | 11073 | src: LazySrcLoc, |
| 10961 | 11074 | ptr: Air.Inst.Ref, |
| 10962 | 11075 | uncasted_operand: Air.Inst.Ref, |
| 10963 | | ) !void { |
| 11076 | ) CompileError!void { |
| 10964 | 11077 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); |
| 10965 | 11078 | } |
| 10966 | 11079 | |
| ... | ... | @@ -10976,7 +11089,7 @@ fn storePtr2( |
| 10976 | 11089 | ) !void { |
| 10977 | 11090 | const ptr_ty = sema.typeOf(ptr); |
| 10978 | 11091 | if (ptr_ty.isConstPtr()) |
| 10979 | | return sema.mod.fail(&block.base, src, "cannot assign to constant", .{}); |
| 11092 | return sema.fail(block, src, "cannot assign to constant", .{}); |
| 10980 | 11093 | |
| 10981 | 11094 | const elem_ty = ptr_ty.elemType(); |
| 10982 | 11095 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); |
| ... | ... | @@ -10985,7 +11098,7 @@ fn storePtr2( |
| 10985 | 11098 | |
| 10986 | 11099 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 10987 | 11100 | const operand_val = (try sema.resolveMaybeUndefVal(block, operand_src, operand)) orelse |
| 10988 | | return sema.mod.fail(&block.base, src, "cannot store runtime value in compile time variable", .{}); |
| 11101 | return sema.fail(block, src, "cannot store runtime value in compile time variable", .{}); |
| 10989 | 11102 | if (ptr_val.tag() == .decl_ref_mut) { |
| 10990 | 11103 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); |
| 10991 | 11104 | return; |
| ... | ... | @@ -11013,21 +11126,21 @@ fn storePtrVal( |
| 11013 | 11126 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { |
| 11014 | 11127 | if (block.runtime_cond) |cond_src| { |
| 11015 | 11128 | const msg = msg: { |
| 11016 | | const msg = try sema.mod.errMsg(&block.base, src, "store to comptime variable depends on runtime condition", .{}); |
| 11129 | const msg = try sema.errMsg(block, src, "store to comptime variable depends on runtime condition", .{}); |
| 11017 | 11130 | errdefer msg.destroy(sema.gpa); |
| 11018 | | try sema.mod.errNote(&block.base, cond_src, msg, "runtime condition here", .{}); |
| 11131 | try sema.errNote(block, cond_src, msg, "runtime condition here", .{}); |
| 11019 | 11132 | break :msg msg; |
| 11020 | 11133 | }; |
| 11021 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11134 | return sema.failWithOwnedErrorMsg(msg); |
| 11022 | 11135 | } |
| 11023 | 11136 | if (block.runtime_loop) |loop_src| { |
| 11024 | 11137 | const msg = msg: { |
| 11025 | | const msg = try sema.mod.errMsg(&block.base, src, "cannot store to comptime variable in non-inline loop", .{}); |
| 11138 | const msg = try sema.errMsg(block, src, "cannot store to comptime variable in non-inline loop", .{}); |
| 11026 | 11139 | errdefer msg.destroy(sema.gpa); |
| 11027 | | try sema.mod.errNote(&block.base, loop_src, msg, "non-inline loop here", .{}); |
| 11140 | try sema.errNote(block, loop_src, msg, "non-inline loop here", .{}); |
| 11028 | 11141 | break :msg msg; |
| 11029 | 11142 | }; |
| 11030 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11143 | return sema.failWithOwnedErrorMsg(msg); |
| 11031 | 11144 | } |
| 11032 | 11145 | unreachable; |
| 11033 | 11146 | } |
| ... | ... | @@ -11191,7 +11304,7 @@ fn analyzeLoad( |
| 11191 | 11304 | const ptr_ty = sema.typeOf(ptr); |
| 11192 | 11305 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 11193 | 11306 | .Pointer => ptr_ty.elemType(), |
| 11194 | | else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| 11307 | else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty}), |
| 11195 | 11308 | }; |
| 11196 | 11309 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 11197 | 11310 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { |
| ... | ... | @@ -11213,7 +11326,7 @@ fn analyzeSliceLen( |
| 11213 | 11326 | if (slice_val.isUndef()) { |
| 11214 | 11327 | return sema.addConstUndef(Type.initTag(.usize)); |
| 11215 | 11328 | } |
| 11216 | | return sema.mod.fail(&block.base, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{}); |
| 11329 | return sema.fail(block, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{}); |
| 11217 | 11330 | } |
| 11218 | 11331 | try sema.requireRuntimeBlock(block, src); |
| 11219 | 11332 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); |
| ... | ... | @@ -11283,7 +11396,7 @@ fn analyzeSlice( |
| 11283 | 11396 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 11284 | 11397 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { |
| 11285 | 11398 | .Pointer => array_ptr_ty.elemType(), |
| 11286 | | else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 11399 | else => return sema.fail(block, src, "expected pointer, found '{}'", .{array_ptr_ty}), |
| 11287 | 11400 | }; |
| 11288 | 11401 | |
| 11289 | 11402 | var array_type = ptr_child; |
| ... | ... | @@ -11296,11 +11409,11 @@ fn analyzeSlice( |
| 11296 | 11409 | break :blk ptr_child.elemType().elemType(); |
| 11297 | 11410 | } |
| 11298 | 11411 | |
| 11299 | | return sema.mod.fail(&block.base, src, "slice of single-item pointer", .{}); |
| 11412 | return sema.fail(block, src, "slice of single-item pointer", .{}); |
| 11300 | 11413 | } |
| 11301 | 11414 | break :blk ptr_child.elemType(); |
| 11302 | 11415 | }, |
| 11303 | | else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}), |
| 11416 | else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_child}), |
| 11304 | 11417 | }; |
| 11305 | 11418 | |
| 11306 | 11419 | const slice_sentinel = if (sentinel_opt != .none) blk: { |
| ... | ... | @@ -11316,7 +11429,7 @@ fn analyzeSlice( |
| 11316 | 11429 | const start_u64 = start_val.toUnsignedInt(); |
| 11317 | 11430 | const end_u64 = end_val.toUnsignedInt(); |
| 11318 | 11431 | if (start_u64 > end_u64) { |
| 11319 | | return sema.mod.fail(&block.base, src, "out of bounds slice", .{}); |
| 11432 | return sema.fail(block, src, "out of bounds slice", .{}); |
| 11320 | 11433 | } |
| 11321 | 11434 | |
| 11322 | 11435 | const len = end_u64 - start_u64; |
| ... | ... | @@ -11341,7 +11454,7 @@ fn analyzeSlice( |
| 11341 | 11454 | }); |
| 11342 | 11455 | _ = return_type; |
| 11343 | 11456 | |
| 11344 | | return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{}); |
| 11457 | return sema.fail(block, src, "TODO implement analysis of slice", .{}); |
| 11345 | 11458 | } |
| 11346 | 11459 | |
| 11347 | 11460 | /// Asserts that lhs and rhs types are both numeric. |
| ... | ... | @@ -11366,13 +11479,13 @@ fn cmpNumeric( |
| 11366 | 11479 | |
| 11367 | 11480 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { |
| 11368 | 11481 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { |
| 11369 | | return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{ |
| 11482 | return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{ |
| 11370 | 11483 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), |
| 11371 | 11484 | }); |
| 11372 | 11485 | } |
| 11373 | | return sema.mod.fail(&block.base, src, "TODO implement support for vectors in cmpNumeric", .{}); |
| 11486 | return sema.fail(block, src, "TODO implement support for vectors in cmpNumeric", .{}); |
| 11374 | 11487 | } else if (lhs_ty_tag == .Vector or rhs_ty_tag == .Vector) { |
| 11375 | | return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{ |
| 11488 | return sema.fail(block, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{ |
| 11376 | 11489 | lhs_ty, rhs_ty, |
| 11377 | 11490 | }); |
| 11378 | 11491 | } |
| ... | ... | @@ -11522,7 +11635,7 @@ fn cmpNumeric( |
| 11522 | 11635 | const dest_type = if (dest_float_type) |ft| ft else blk: { |
| 11523 | 11636 | const max_bits = std.math.max(lhs_bits, rhs_bits); |
| 11524 | 11637 | const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { |
| 11525 | | error.Overflow => return sema.mod.fail(&block.base, src, "{d} exceeds maximum integer bit count", .{max_bits}), |
| 11638 | error.Overflow => return sema.fail(block, src, "{d} exceeds maximum integer bit count", .{max_bits}), |
| 11526 | 11639 | }; |
| 11527 | 11640 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; |
| 11528 | 11641 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); |
| ... | ... | @@ -11569,8 +11682,8 @@ fn wrapErrorUnion( |
| 11569 | 11682 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11570 | 11683 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; |
| 11571 | 11684 | if (!mem.eql(u8, expected_name, n)) { |
| 11572 | | return sema.mod.fail( |
| 11573 | | &block.base, |
| 11685 | return sema.fail( |
| 11686 | block, |
| 11574 | 11687 | inst_src, |
| 11575 | 11688 | "expected type '{}', found type '{}'", |
| 11576 | 11689 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11587,8 +11700,8 @@ fn wrapErrorUnion( |
| 11587 | 11700 | if (mem.eql(u8, expected_name, name)) break true; |
| 11588 | 11701 | } else false; |
| 11589 | 11702 | if (!found) { |
| 11590 | | return sema.mod.fail( |
| 11591 | | &block.base, |
| 11703 | return sema.fail( |
| 11704 | block, |
| 11592 | 11705 | inst_src, |
| 11593 | 11706 | "expected type '{}', found type '{}'", |
| 11594 | 11707 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11599,8 +11712,8 @@ fn wrapErrorUnion( |
| 11599 | 11712 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11600 | 11713 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; |
| 11601 | 11714 | if (!map.contains(expected_name)) { |
| 11602 | | return sema.mod.fail( |
| 11603 | | &block.base, |
| 11715 | return sema.fail( |
| 11716 | block, |
| 11604 | 11717 | inst_src, |
| 11605 | 11718 | "expected type '{}', found type '{}'", |
| 11606 | 11719 | .{ dest_err_set_ty, inst_ty }, |
| ... | ... | @@ -11735,18 +11848,18 @@ fn resolvePeerTypes( |
| 11735 | 11848 | ); |
| 11736 | 11849 | |
| 11737 | 11850 | const msg = msg: { |
| 11738 | | const msg = try sema.mod.errMsg(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty }); |
| 11851 | const msg = try sema.errMsg(block, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty }); |
| 11739 | 11852 | errdefer msg.destroy(sema.gpa); |
| 11740 | 11853 | |
| 11741 | 11854 | if (chosen_src) |src_loc| |
| 11742 | | try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{chosen_ty}); |
| 11855 | try sema.errNote(block, src_loc, msg, "type '{}' here", .{chosen_ty}); |
| 11743 | 11856 | |
| 11744 | 11857 | if (candidate_src) |src_loc| |
| 11745 | | try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{candidate_ty}); |
| 11858 | try sema.errNote(block, src_loc, msg, "type '{}' here", .{candidate_ty}); |
| 11746 | 11859 | |
| 11747 | 11860 | break :msg msg; |
| 11748 | 11861 | }; |
| 11749 | | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); |
| 11862 | return sema.failWithOwnedErrorMsg(msg); |
| 11750 | 11863 | } |
| 11751 | 11864 | |
| 11752 | 11865 | return sema.typeOf(chosen); |
| ... | ... | @@ -11765,7 +11878,7 @@ pub fn resolveTypeLayout( |
| 11765 | 11878 | switch (struct_obj.status) { |
| 11766 | 11879 | .none, .have_field_types => {}, |
| 11767 | 11880 | .field_types_wip, .layout_wip => { |
| 11768 | | return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty}); |
| 11881 | return sema.fail(block, src, "struct {} depends on itself", .{ty}); |
| 11769 | 11882 | }, |
| 11770 | 11883 | .have_layout => return, |
| 11771 | 11884 | } |
| ... | ... | @@ -11786,7 +11899,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11786 | 11899 | switch (struct_obj.status) { |
| 11787 | 11900 | .none => {}, |
| 11788 | 11901 | .field_types_wip => { |
| 11789 | | return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty}); |
| 11902 | return sema.fail(block, src, "struct {} depends on itself", .{ty}); |
| 11790 | 11903 | }, |
| 11791 | 11904 | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11792 | 11905 | } |
| ... | ... | @@ -11813,7 +11926,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11813 | 11926 | switch (union_obj.status) { |
| 11814 | 11927 | .none => {}, |
| 11815 | 11928 | .field_types_wip => { |
| 11816 | | return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty}); |
| 11929 | return sema.fail(block, src, "union {} depends on itself", .{ty}); |
| 11817 | 11930 | }, |
| 11818 | 11931 | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11819 | 11932 | } |
| ... | ... | @@ -12232,7 +12345,7 @@ fn generateUnionTagTypeNumbered( |
| 12232 | 12345 | .val = enum_val, |
| 12233 | 12346 | }); |
| 12234 | 12347 | new_decl.owns_tv = true; |
| 12235 | | errdefer sema.mod.abortAnonDecl(new_decl); |
| 12348 | errdefer mod.abortAnonDecl(new_decl); |
| 12236 | 12349 | |
| 12237 | 12350 | enum_obj.* = .{ |
| 12238 | 12351 | .owner_decl = new_decl, |
| ... | ... | @@ -12268,7 +12381,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12268 | 12381 | .val = enum_val, |
| 12269 | 12382 | }); |
| 12270 | 12383 | new_decl.owns_tv = true; |
| 12271 | | errdefer sema.mod.abortAnonDecl(new_decl); |
| 12384 | errdefer mod.abortAnonDecl(new_decl); |
| 12272 | 12385 | |
| 12273 | 12386 | enum_obj.* = .{ |
| 12274 | 12387 | .owner_decl = new_decl, |
| ... | ... | @@ -12752,8 +12865,8 @@ pub fn analyzeAddrspace( |
| 12752 | 12865 | .pointer => "pointers", |
| 12753 | 12866 | }; |
| 12754 | 12867 | |
| 12755 | | return sema.mod.fail( |
| 12756 | | &block.base, |
| 12868 | return sema.fail( |
| 12869 | block, |
| 12757 | 12870 | src, |
| 12758 | 12871 | "{s} with address space '{s}' are not supported on {s}", |
| 12759 | 12872 | .{ entity, @tagName(address_space), arch.genericName() }, |