| ... | @@ -880,19 +880,76 @@ fn resolveMaybeUndefValAllowVariables( | ... | @@ -880,19 +880,76 @@ fn resolveMaybeUndefValAllowVariables( |
| 880 | } | 880 | } |
| 881 | | 881 | |
| 882 | fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { | 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 | fn failWithUseOfUndef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { | 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 | fn failWithDivideByZero(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError { | 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 | fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError { | 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 | /// Appropriate to call when the coercion has already been done by result | 955 | /// Appropriate to call when the coercion has already been done by result |
| ... | @@ -923,9 +980,9 @@ fn resolveAlign( | ... | @@ -923,9 +980,9 @@ fn resolveAlign( |
| 923 | ) !u16 { | 980 | ) !u16 { |
| 924 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); | 981 | const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16)); |
| 925 | const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line. | 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 | if (!std.math.isPowerOfTwo(alignment)) { | 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 | alignment, | 986 | alignment, |
| 930 | }); | 987 | }); |
| 931 | } | 988 | } |
| ... | @@ -981,7 +1038,7 @@ pub fn resolveInstValue( | ... | @@ -981,7 +1038,7 @@ pub fn resolveInstValue( |
| 981 | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 1038 | fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 982 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1039 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 983 | const src = inst_data.src(); | 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 | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 1044 | fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -1177,7 +1234,7 @@ fn zirEnumDecl( | ... | @@ -1177,7 +1234,7 @@ fn zirEnumDecl( |
| 1177 | .val = enum_val, | 1234 | .val = enum_val, |
| 1178 | }, type_name); | 1235 | }, type_name); |
| 1179 | new_decl.owns_tv = true; | 1236 | new_decl.owns_tv = true; |
| 1180 | errdefer sema.mod.abortAnonDecl(new_decl); | 1237 | errdefer mod.abortAnonDecl(new_decl); |
| 1181 | | 1238 | |
| 1182 | enum_obj.* = .{ | 1239 | enum_obj.* = .{ |
| 1183 | .owner_decl = new_decl, | 1240 | .owner_decl = new_decl, |
| ... | @@ -1292,12 +1349,12 @@ fn zirEnumDecl( | ... | @@ -1292,12 +1349,12 @@ fn zirEnumDecl( |
| 1292 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); | 1349 | const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i); |
| 1293 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); | 1350 | const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index); |
| 1294 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 1355 | break :msg msg; |
| 1299 | }; | 1356 | }; |
| 1300 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 1357 | return sema.failWithOwnedErrorMsg(msg); |
| 1301 | } | 1358 | } |
| 1302 | | 1359 | |
| 1303 | if (has_tag_value) { | 1360 | if (has_tag_value) { |
| ... | @@ -1400,7 +1457,7 @@ fn zirOpaqueDecl( | ... | @@ -1400,7 +1457,7 @@ fn zirOpaqueDecl( |
| 1400 | | 1457 | |
| 1401 | _ = extended; | 1458 | _ = extended; |
| 1402 | _ = inst; | 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 | fn zirErrorSetDecl( | 1463 | fn zirErrorSetDecl( |
| ... | @@ -1509,7 +1566,7 @@ fn ensureResultUsed( | ... | @@ -1509,7 +1566,7 @@ fn ensureResultUsed( |
| 1509 | const operand_ty = sema.typeOf(operand); | 1566 | const operand_ty = sema.typeOf(operand); |
| 1510 | switch (operand_ty.zigTypeTag()) { | 1567 | switch (operand_ty.zigTypeTag()) { |
| 1511 | .Void, .NoReturn => return, | 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,7 +1579,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1522 | const src = inst_data.src(); | 1579 | const src = inst_data.src(); |
| 1523 | const operand_ty = sema.typeOf(operand); | 1580 | const operand_ty = sema.typeOf(operand); |
| 1524 | switch (operand_ty.zigTypeTag()) { | 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 | else => return, | 1583 | else => return, |
| 1527 | } | 1584 | } |
| 1528 | } | 1585 | } |
| ... | @@ -1548,15 +1605,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co | ... | @@ -1548,15 +1605,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1548 | } | 1605 | } |
| 1549 | if (!elem_ty.isIndexable()) { | 1606 | if (!elem_ty.isIndexable()) { |
| 1550 | const msg = msg: { | 1607 | const msg = msg: { |
| 1551 | const msg = try sema.mod.errMsg( | 1608 | const msg = try sema.errMsg( |
| 1552 | &block.base, | 1609 | block, |
| 1553 | src, | 1610 | src, |
| 1554 | "type '{}' does not support indexing", | 1611 | "type '{}' does not support indexing", |
| 1555 | .{elem_ty}, | 1612 | .{elem_ty}, |
| 1556 | ); | 1613 | ); |
| 1557 | errdefer msg.destroy(sema.gpa); | 1614 | errdefer msg.destroy(sema.gpa); |
| 1558 | try sema.mod.errNote( | 1615 | try sema.errNote( |
| 1559 | &block.base, | 1616 | block, |
| 1560 | src, | 1617 | src, |
| 1561 | msg, | 1618 | msg, |
| 1562 | "for loop operand must be an array, slice, tuple, or vector", | 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,13 +1621,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1564 | ); | 1621 | ); |
| 1565 | break :msg msg; | 1622 | break :msg msg; |
| 1566 | }; | 1623 | }; |
| 1567 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 1624 | return sema.failWithOwnedErrorMsg(msg); |
| 1568 | } | 1625 | } |
| 1569 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); | 1626 | const result_ptr = try sema.fieldPtr(block, src, array, "len", src); |
| 1570 | return sema.analyzeLoad(block, src, result_ptr, src); | 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 | fn zirAllocExtended( | 1633 | fn zirAllocExtended( |
| ... | @@ -1591,7 +1648,7 @@ fn zirAllocExtended( | ... | @@ -1591,7 +1648,7 @@ fn zirAllocExtended( |
| 1591 | extra_index += 1; | 1648 | extra_index += 1; |
| 1592 | break :blk try sema.resolveType(block, ty_src, type_ref); | 1649 | break :blk try sema.resolveType(block, ty_src, type_ref); |
| 1593 | } else { | 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 | const alignment: u16 = if (small.has_align) blk: { | 1654 | const alignment: u16 = if (small.has_align) blk: { |
| ... | @@ -1602,11 +1659,11 @@ fn zirAllocExtended( | ... | @@ -1602,11 +1659,11 @@ fn zirAllocExtended( |
| 1602 | } else 0; | 1659 | } else 0; |
| 1603 | | 1660 | |
| 1604 | if (small.is_comptime) { | 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 | if (!small.is_const) { | 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 | const ptr_type = try Type.ptr(sema.arena, .{ | 1669 | const ptr_type = try Type.ptr(sema.arena, .{ |
| ... | @@ -1804,12 +1861,10 @@ fn validateUnionInitPtr( | ... | @@ -1804,12 +1861,10 @@ fn validateUnionInitPtr( |
| 1804 | instrs: []const Zir.Inst.Index, | 1861 | instrs: []const Zir.Inst.Index, |
| 1805 | union_ptr: Air.Inst.Ref, | 1862 | union_ptr: Air.Inst.Ref, |
| 1806 | ) CompileError!void { | 1863 | ) CompileError!void { |
| 1807 | const mod = sema.mod; | | |
| 1808 | | | |
| 1809 | if (instrs.len != 1) { | 1864 | if (instrs.len != 1) { |
| 1810 | // TODO add note for other field | 1865 | // TODO add note for other field |
| 1811 | // TODO add note for union declared here | 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 | const field_ptr = instrs[0]; | 1870 | const field_ptr = instrs[0]; |
| ... | @@ -1845,7 +1900,6 @@ fn validateStructInitPtr( | ... | @@ -1845,7 +1900,6 @@ fn validateStructInitPtr( |
| 1845 | instrs: []const Zir.Inst.Index, | 1900 | instrs: []const Zir.Inst.Index, |
| 1846 | ) CompileError!void { | 1901 | ) CompileError!void { |
| 1847 | const gpa = sema.gpa; | 1902 | const gpa = sema.gpa; |
| 1848 | const mod = sema.mod; | | |
| 1849 | | 1903 | |
| 1850 | // Maps field index to field_ptr index of where it was already initialized. | 1904 | // Maps field index to field_ptr index of where it was already initialized. |
| 1851 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); | 1905 | const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count()); |
| ... | @@ -1864,12 +1918,12 @@ fn validateStructInitPtr( | ... | @@ -1864,12 +1918,12 @@ fn validateStructInitPtr( |
| 1864 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; | 1918 | const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node; |
| 1865 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; | 1919 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node }; |
| 1866 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 1924 | break :msg msg; |
| 1871 | }; | 1925 | }; |
| 1872 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 1926 | return sema.failWithOwnedErrorMsg(msg); |
| 1873 | } | 1927 | } |
| 1874 | found_fields[field_index] = field_ptr; | 1928 | found_fields[field_index] = field_ptr; |
| 1875 | } | 1929 | } |
| ... | @@ -1884,28 +1938,28 @@ fn validateStructInitPtr( | ... | @@ -1884,28 +1938,28 @@ fn validateStructInitPtr( |
| 1884 | const template = "missing struct field: {s}"; | 1938 | const template = "missing struct field: {s}"; |
| 1885 | const args = .{field_name}; | 1939 | const args = .{field_name}; |
| 1886 | if (root_msg) |msg| { | 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 | } else { | 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 | if (root_msg) |msg| { | 1946 | if (root_msg) |msg| { |
| 1893 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 1947 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1894 | defer gpa.free(fqn); | 1948 | defer gpa.free(fqn); |
| 1895 | try mod.errNoteNonLazy( | 1949 | try sema.mod.errNoteNonLazy( |
| 1896 | struct_obj.srcLoc(), | 1950 | struct_obj.srcLoc(), |
| 1897 | msg, | 1951 | msg, |
| 1898 | "struct '{s}' declared here", | 1952 | "struct '{s}' declared here", |
| 1899 | .{fqn}, | 1953 | .{fqn}, |
| 1900 | ); | 1954 | ); |
| 1901 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 1955 | return sema.failWithOwnedErrorMsg(msg); |
| 1902 | } | 1956 | } |
| 1903 | } | 1957 | } |
| 1904 | | 1958 | |
| 1905 | fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 1959 | fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 1906 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 1960 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 1907 | const src = inst_data.src(); | 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 | fn failWithBadFieldAccess( | 1965 | fn failWithBadFieldAccess( |
| ... | @@ -1915,24 +1969,23 @@ fn failWithBadFieldAccess( | ... | @@ -1915,24 +1969,23 @@ fn failWithBadFieldAccess( |
| 1915 | field_src: LazySrcLoc, | 1969 | field_src: LazySrcLoc, |
| 1916 | field_name: []const u8, | 1970 | field_name: []const u8, |
| 1917 | ) CompileError { | 1971 | ) CompileError { |
| 1918 | const mod = sema.mod; | | |
| 1919 | const gpa = sema.gpa; | 1972 | const gpa = sema.gpa; |
| 1920 | | 1973 | |
| 1921 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 1974 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 1922 | defer gpa.free(fqn); | 1975 | defer gpa.free(fqn); |
| 1923 | | 1976 | |
| 1924 | const msg = msg: { | 1977 | const msg = msg: { |
| 1925 | const msg = try mod.errMsg( | 1978 | const msg = try sema.errMsg( |
| 1926 | &block.base, | 1979 | block, |
| 1927 | field_src, | 1980 | field_src, |
| 1928 | "no field named '{s}' in struct '{s}'", | 1981 | "no field named '{s}' in struct '{s}'", |
| 1929 | .{ field_name, fqn }, | 1982 | .{ field_name, fqn }, |
| 1930 | ); | 1983 | ); |
| 1931 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 1986 | break :msg msg; |
| 1934 | }; | 1987 | }; |
| 1935 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 1988 | return sema.failWithOwnedErrorMsg(msg); |
| 1936 | } | 1989 | } |
| 1937 | | 1990 | |
| 1938 | fn failWithBadUnionFieldAccess( | 1991 | fn failWithBadUnionFieldAccess( |
| ... | @@ -1942,24 +1995,23 @@ fn failWithBadUnionFieldAccess( | ... | @@ -1942,24 +1995,23 @@ fn failWithBadUnionFieldAccess( |
| 1942 | field_src: LazySrcLoc, | 1995 | field_src: LazySrcLoc, |
| 1943 | field_name: []const u8, | 1996 | field_name: []const u8, |
| 1944 | ) CompileError { | 1997 | ) CompileError { |
| 1945 | const mod = sema.mod; | | |
| 1946 | const gpa = sema.gpa; | 1998 | const gpa = sema.gpa; |
| 1947 | | 1999 | |
| 1948 | const fqn = try union_obj.getFullyQualifiedName(gpa); | 2000 | const fqn = try union_obj.getFullyQualifiedName(gpa); |
| 1949 | defer gpa.free(fqn); | 2001 | defer gpa.free(fqn); |
| 1950 | | 2002 | |
| 1951 | const msg = msg: { | 2003 | const msg = msg: { |
| 1952 | const msg = try mod.errMsg( | 2004 | const msg = try sema.errMsg( |
| 1953 | &block.base, | 2005 | block, |
| 1954 | field_src, | 2006 | field_src, |
| 1955 | "no field named '{s}' in union '{s}'", | 2007 | "no field named '{s}' in union '{s}'", |
| 1956 | .{ field_name, fqn }, | 2008 | .{ field_name, fqn }, |
| 1957 | ); | 2009 | ); |
| 1958 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 2012 | break :msg msg; |
| 1961 | }; | 2013 | }; |
| 1962 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2014 | return sema.failWithOwnedErrorMsg(msg); |
| 1963 | } | 2015 | } |
| 1964 | | 2016 | |
| 1965 | fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 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,7 +2202,7 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 2150 | const src = inst_data.src(); | 2202 | const src = inst_data.src(); |
| 2151 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 2203 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2152 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand); | 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 | fn zirCompileLog( | 2208 | fn zirCompileLog( |
| ... | @@ -2269,7 +2321,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2269,7 +2321,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2269 | | 2321 | |
| 2270 | // we check this here to avoid undefined symbols | 2322 | // we check this here to avoid undefined symbols |
| 2271 | if (!@import("build_options").have_llvm) | 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 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); | 2326 | var c_import_buf = std.ArrayList(u8).init(sema.gpa); |
| 2275 | defer c_import_buf.deinit(); | 2327 | defer c_import_buf.deinit(); |
| ... | @@ -2290,15 +2342,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2290,15 +2342,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2290 | _ = try sema.analyzeBody(&child_block, body); | 2342 | _ = try sema.analyzeBody(&child_block, body); |
| 2291 | | 2343 | |
| 2292 | const c_import_res = sema.mod.comp.cImport(c_import_buf.items) catch |err| | 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 | if (c_import_res.errors.len != 0) { | 2347 | if (c_import_res.errors.len != 0) { |
| 2296 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 2350 | errdefer msg.destroy(sema.gpa); |
| 2299 | | 2351 | |
| 2300 | if (!sema.mod.comp.bin_file.options.link_libc) | 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 | for (c_import_res.errors) |_| { | 2355 | for (c_import_res.errors) |_| { |
| 2304 | // TODO integrate with LazySrcLoc | 2356 | // TODO integrate with LazySrcLoc |
| ... | @@ -2310,7 +2362,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2310,7 +2362,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2310 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); | 2362 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); |
| 2311 | break :msg msg; | 2363 | break :msg msg; |
| 2312 | }; | 2364 | }; |
| 2313 | return sema.mod.failWithOwnedErrorMsg(&child_block.base, msg); | 2365 | return sema.failWithOwnedErrorMsg(msg); |
| 2314 | } | 2366 | } |
| 2315 | const c_import_pkg = Package.create( | 2367 | const c_import_pkg = Package.create( |
| 2316 | sema.gpa, | 2368 | sema.gpa, |
| ... | @@ -2326,10 +2378,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -2326,10 +2378,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2326 | try c_import_pkg.add(sema.gpa, "std", std_pkg); | 2378 | try c_import_pkg.add(sema.gpa, "std", std_pkg); |
| 2327 | | 2379 | |
| 2328 | const result = sema.mod.importPkg(c_import_pkg) catch |err| | 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 | sema.mod.astGenFile(result.file) catch |err| | 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 | try sema.mod.semaFile(result.file); | 2386 | try sema.mod.semaFile(result.file); |
| 2335 | const file_root_decl = result.file.root_decl.?; | 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,7 +2392,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 2340 | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 2392 | fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 2341 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 2393 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 2342 | const src = inst_data.src(); | 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 | fn zirBlock( | 2398 | fn zirBlock( |
| ... | @@ -2527,11 +2579,11 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -2527,11 +2579,11 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 2527 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 2579 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 2528 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); | 2580 | const decl_name = sema.code.nullTerminatedString(extra.decl_name); |
| 2529 | if (extra.namespace != .none) { | 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 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); | 2584 | const decl = try sema.lookupIdentifier(block, operand_src, decl_name); |
| 2533 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 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 | fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 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,40 +2599,117 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 2547 | const options = try sema.resolveExportOptions(block, options_src, extra.options); | 2599 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 2548 | const decl = switch (operand.val.tag()) { | 2600 | const decl = switch (operand.val.tag()) { |
| 2549 | .function => operand.val.castTag(.function).?.data.owner_decl, | 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 | const mod = sema.mod; | 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 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2686 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2558 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 2687 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 2559 | const src: LazySrcLoc = inst_data.src(); | 2688 | const src: LazySrcLoc = inst_data.src(); |
| 2560 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); | 2689 | const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand); |
| 2561 | if (alignment > 256) { | 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 | alignment, | 2692 | alignment, |
| 2564 | }); | 2693 | }); |
| 2565 | } | 2694 | } |
| 2566 | const func = sema.owner_func orelse | 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 | switch (func.owner_decl.ty.fnCallingConvention()) { | 2698 | switch (func.owner_decl.ty.fnCallingConvention()) { |
| 2570 | .Naked => return mod.fail(&block.base, src, "@setAlignStack in naked function", .{}), | 2699 | .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), |
| 2571 | .Inline => return mod.fail(&block.base, src, "@setAlignStack in inline function", .{}), | 2700 | .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), |
| 2572 | else => {}, | 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 | if (gop.found_existing) { | 2705 | if (gop.found_existing) { |
| 2577 | const msg = msg: { | 2706 | const msg = msg: { |
| 2578 | const msg = try mod.errMsg(&block.base, src, "multiple @setAlignStack in the same function body", .{}); | 2707 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); |
| 2579 | errdefer msg.destroy(mod.gpa); | 2708 | errdefer msg.destroy(sema.gpa); |
| 2580 | try mod.errNote(&block.base, src, msg, "other instance here", .{}); | 2709 | try sema.errNote(block, src, msg, "other instance here", .{}); |
| 2581 | break :msg msg; | 2710 | break :msg msg; |
| 2582 | }; | 2711 | }; |
| 2583 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2712 | return sema.failWithOwnedErrorMsg(msg); |
| 2584 | } | 2713 | } |
| 2585 | gop.value_ptr.* = .{ .alignment = alignment, .src = src }; | 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,7 +2725,7 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 2596 | fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 2725 | fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { |
| 2597 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 2726 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 2598 | const src: LazySrcLoc = inst_data.src(); | 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 | fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 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,7 +2742,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 2613 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); | 2742 | const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand); |
| 2614 | | 2743 | |
| 2615 | if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) { | 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 | _ = try block.addInst(.{ | 2748 | _ = try block.addInst(.{ |
| ... | @@ -2757,7 +2886,7 @@ fn lookupInNamespace( | ... | @@ -2757,7 +2886,7 @@ fn lookupInNamespace( |
| 2757 | }, | 2886 | }, |
| 2758 | else => { | 2887 | else => { |
| 2759 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 2890 | errdefer msg.destroy(gpa); |
| 2762 | for (candidates.items) |candidate| { | 2891 | for (candidates.items) |candidate| { |
| 2763 | const src_loc = candidate.srcLoc(); | 2892 | const src_loc = candidate.srcLoc(); |
| ... | @@ -2765,7 +2894,7 @@ fn lookupInNamespace( | ... | @@ -2765,7 +2894,7 @@ fn lookupInNamespace( |
| 2765 | } | 2894 | } |
| 2766 | break :msg msg; | 2895 | break :msg msg; |
| 2767 | }; | 2896 | }; |
| 2768 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 2897 | return sema.failWithOwnedErrorMsg(msg); |
| 2769 | }, | 2898 | }, |
| 2770 | } | 2899 | } |
| 2771 | } else if (namespace.decls.get(ident_name)) |decl| { | 2900 | } else if (namespace.decls.get(ident_name)) |decl| { |
| ... | @@ -2899,14 +3028,14 @@ fn analyzeCall( | ... | @@ -2899,14 +3028,14 @@ fn analyzeCall( |
| 2899 | | 3028 | |
| 2900 | const func_ty = sema.typeOf(func); | 3029 | const func_ty = sema.typeOf(func); |
| 2901 | if (func_ty.zigTypeTag() != .Fn) | 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 | const func_ty_info = func_ty.fnInfo(); | 3033 | const func_ty_info = func_ty.fnInfo(); |
| 2905 | const cc = func_ty_info.cc; | 3034 | const cc = func_ty_info.cc; |
| 2906 | if (cc == .Naked) { | 3035 | if (cc == .Naked) { |
| 2907 | // TODO add error note: declared here | 3036 | // TODO add error note: declared here |
| 2908 | return mod.fail( | 3037 | return sema.fail( |
| 2909 | &block.base, | 3038 | block, |
| 2910 | func_src, | 3039 | func_src, |
| 2911 | "unable to call function with naked calling convention", | 3040 | "unable to call function with naked calling convention", |
| 2912 | .{}, | 3041 | .{}, |
| ... | @@ -2917,8 +3046,8 @@ fn analyzeCall( | ... | @@ -2917,8 +3046,8 @@ fn analyzeCall( |
| 2917 | assert(cc == .C); | 3046 | assert(cc == .C); |
| 2918 | if (uncasted_args.len < fn_params_len) { | 3047 | if (uncasted_args.len < fn_params_len) { |
| 2919 | // TODO add error note: declared here | 3048 | // TODO add error note: declared here |
| 2920 | return mod.fail( | 3049 | return sema.fail( |
| 2921 | &block.base, | 3050 | block, |
| 2922 | func_src, | 3051 | func_src, |
| 2923 | "expected at least {d} argument(s), found {d}", | 3052 | "expected at least {d} argument(s), found {d}", |
| 2924 | .{ fn_params_len, uncasted_args.len }, | 3053 | .{ fn_params_len, uncasted_args.len }, |
| ... | @@ -2926,8 +3055,8 @@ fn analyzeCall( | ... | @@ -2926,8 +3055,8 @@ fn analyzeCall( |
| 2926 | } | 3055 | } |
| 2927 | } else if (fn_params_len != uncasted_args.len) { | 3056 | } else if (fn_params_len != uncasted_args.len) { |
| 2928 | // TODO add error note: declared here | 3057 | // TODO add error note: declared here |
| 2929 | return mod.fail( | 3058 | return sema.fail( |
| 2930 | &block.base, | 3059 | block, |
| 2931 | func_src, | 3060 | func_src, |
| 2932 | "expected {d} argument(s), found {d}", | 3061 | "expected {d} argument(s), found {d}", |
| 2933 | .{ fn_params_len, uncasted_args.len }, | 3062 | .{ fn_params_len, uncasted_args.len }, |
| ... | @@ -2945,7 +3074,7 @@ fn analyzeCall( | ... | @@ -2945,7 +3074,7 @@ fn analyzeCall( |
| 2945 | .never_inline, | 3074 | .never_inline, |
| 2946 | .no_async, | 3075 | .no_async, |
| 2947 | .always_tail, | 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 | modifier, | 3078 | modifier, |
| 2950 | }), | 3079 | }), |
| 2951 | } | 3080 | } |
| ... | @@ -2960,7 +3089,7 @@ fn analyzeCall( | ... | @@ -2960,7 +3089,7 @@ fn analyzeCall( |
| 2960 | const func_val = try sema.resolveConstValue(block, func_src, func); | 3089 | const func_val = try sema.resolveConstValue(block, func_src, func); |
| 2961 | const module_fn = switch (func_val.tag()) { | 3090 | const module_fn = switch (func_val.tag()) { |
| 2962 | .function => func_val.castTag(.function).?.data, | 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 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), | 3093 | @as([]const u8, if (is_comptime_call) "comptime" else "inline"), |
| 2965 | }), | 3094 | }), |
| 2966 | else => unreachable, | 3095 | else => unreachable, |
| ... | @@ -3633,7 +3762,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com | ... | @@ -3633,7 +3762,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3633 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); | 3762 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 3634 | | 3763 | |
| 3635 | if (error_union.zigTypeTag() != .ErrorSet) { | 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 | error_union.elemType(), | 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,7 +3828,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3699 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { | 3828 | if (try sema.resolveDefinedValue(block, operand_src, op)) |value| { |
| 3700 | const int = value.toUnsignedInt(); | 3829 | const int = value.toUnsignedInt(); |
| 3701 | if (int > sema.mod.global_error_set.count() or int == 0) | 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 | const payload = try sema.arena.create(Value.Payload.Error); | 3832 | const payload = try sema.arena.create(Value.Payload.Error); |
| 3704 | payload.* = .{ | 3833 | payload.* = .{ |
| 3705 | .base = .{ .tag = .@"error" }, | 3834 | .base = .{ .tag = .@"error" }, |
| ... | @@ -3709,7 +3838,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile | ... | @@ -3709,7 +3838,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 3709 | } | 3838 | } |
| 3710 | try sema.requireRuntimeBlock(block, src); | 3839 | try sema.requireRuntimeBlock(block, src); |
| 3711 | if (block.wantSafety()) { | 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 | // const is_gt_max = @panic("TODO get max errors in compilation"); | 3842 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 3714 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); | 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,19 +3858,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com |
| 3729 | const rhs = sema.resolveInst(extra.rhs); | 3858 | const rhs = sema.resolveInst(extra.rhs); |
| 3730 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { | 3859 | if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) { |
| 3731 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 3864 | break :msg msg; |
| 3736 | }; | 3865 | }; |
| 3737 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 3866 | return sema.failWithOwnedErrorMsg(msg); |
| 3738 | } | 3867 | } |
| 3739 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); | 3868 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 3740 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); | 3869 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| 3741 | if (lhs_ty.zigTypeTag() != .ErrorSet) | 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 | if (rhs_ty.zigTypeTag() != .ErrorSet) | 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 | // Anything merged with anyerror is anyerror. | 3875 | // Anything merged with anyerror is anyerror. |
| 3747 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { | 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,7 +3943,6 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 3814 | } | 3943 | } |
| 3815 | | 3944 | |
| 3816 | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 3945 | fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3817 | const mod = sema.mod; | | |
| 3818 | const arena = sema.arena; | 3946 | const arena = sema.arena; |
| 3819 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 3947 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 3820 | const src = inst_data.src(); | 3948 | const src = inst_data.src(); |
| ... | @@ -3826,17 +3954,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3826,17 +3954,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3826 | .Enum => operand, | 3954 | .Enum => operand, |
| 3827 | .Union => { | 3955 | .Union => { |
| 3828 | //if (!operand_ty.unionHasTag()) { | 3956 | //if (!operand_ty.unionHasTag()) { |
| 3829 | // return mod.fail( | 3957 | // return sema.fail( |
| 3830 | // &block.base, | 3958 | // block, |
| 3831 | // operand_src, | 3959 | // operand_src, |
| 3832 | // "untagged union '{}' cannot be converted to integer", | 3960 | // "untagged union '{}' cannot be converted to integer", |
| 3833 | // .{dest_ty_src}, | 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 | else => { | 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 | operand_ty, | 3968 | operand_ty, |
| 3841 | }); | 3969 | }); |
| 3842 | }, | 3970 | }, |
| ... | @@ -3861,8 +3989,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3861,8 +3989,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3861 | } | 3989 | } |
| 3862 | | 3990 | |
| 3863 | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 3991 | fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 3864 | const mod = sema.mod; | 3992 | const target = sema.mod.getTarget(); |
| 3865 | const target = mod.getTarget(); | | |
| 3866 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 3993 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 3867 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 3994 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 3868 | const src = inst_data.src(); | 3995 | const src = inst_data.src(); |
| ... | @@ -3872,7 +3999,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3872,7 +3999,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3872 | const operand = sema.resolveInst(extra.rhs); | 3999 | const operand = sema.resolveInst(extra.rhs); |
| 3873 | | 4000 | |
| 3874 | if (dest_ty.zigTypeTag() != .Enum) { | 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 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { | 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,14 +4011,14 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3884 | } | 4011 | } |
| 3885 | if (!dest_ty.enumHasInt(int_val, target)) { | 4012 | if (!dest_ty.enumHasInt(int_val, target)) { |
| 3886 | const msg = msg: { | 4013 | const msg = msg: { |
| 3887 | const msg = try mod.errMsg( | 4014 | const msg = try sema.errMsg( |
| 3888 | &block.base, | 4015 | block, |
| 3889 | src, | 4016 | src, |
| 3890 | "enum '{}' has no tag with value {}", | 4017 | "enum '{}' has no tag with value {}", |
| 3891 | .{ dest_ty, int_val }, | 4018 | .{ dest_ty, int_val }, |
| 3892 | ); | 4019 | ); |
| 3893 | errdefer msg.destroy(sema.gpa); | 4020 | errdefer msg.destroy(sema.gpa); |
| 3894 | try mod.errNoteNonLazy( | 4021 | try sema.mod.errNoteNonLazy( |
| 3895 | dest_ty.declSrcLoc(), | 4022 | dest_ty.declSrcLoc(), |
| 3896 | msg, | 4023 | msg, |
| 3897 | "enum declared here", | 4024 | "enum declared here", |
| ... | @@ -3899,7 +4026,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3899,7 +4026,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 3899 | ); | 4026 | ); |
| 3900 | break :msg msg; | 4027 | break :msg msg; |
| 3901 | }; | 4028 | }; |
| 3902 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 4029 | return sema.failWithOwnedErrorMsg(msg); |
| 3903 | } | 4030 | } |
| 3904 | return sema.addConstant(dest_ty, int_val); | 4031 | return sema.addConstant(dest_ty, int_val); |
| 3905 | } | 4032 | } |
| ... | @@ -3926,7 +4053,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -3926,7 +4053,7 @@ fn zirOptionalPayloadPtr( |
| 3926 | | 4053 | |
| 3927 | const opt_type = optional_ptr_ty.elemType(); | 4054 | const opt_type = optional_ptr_ty.elemType(); |
| 3928 | if (opt_type.zigTypeTag() != .Optional) { | 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 | const child_type = try opt_type.optionalChildAlloc(sema.arena); | 4059 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| ... | @@ -3939,7 +4066,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -3939,7 +4066,7 @@ fn zirOptionalPayloadPtr( |
| 3939 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { | 4066 | if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| { |
| 3940 | if (try pointer_val.pointerDeref(sema.arena)) |val| { | 4067 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 3941 | if (val.isNull()) { | 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 | // The same Value represents the pointer to the optional and the payload. | 4071 | // The same Value represents the pointer to the optional and the payload. |
| 3945 | return sema.addConstant( | 4072 | return sema.addConstant( |
| ... | @@ -3973,14 +4100,14 @@ fn zirOptionalPayload( | ... | @@ -3973,14 +4100,14 @@ fn zirOptionalPayload( |
| 3973 | const operand_ty = sema.typeOf(operand); | 4100 | const operand_ty = sema.typeOf(operand); |
| 3974 | const opt_type = operand_ty; | 4101 | const opt_type = operand_ty; |
| 3975 | if (opt_type.zigTypeTag() != .Optional) { | 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 | const child_type = try opt_type.optionalChildAlloc(sema.arena); | 4106 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 3980 | | 4107 | |
| 3981 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 4108 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 3982 | if (val.isNull()) { | 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 | const sub_val = val.castTag(.opt_payload).?.data; | 4112 | const sub_val = val.castTag(.opt_payload).?.data; |
| 3986 | return sema.addConstant(child_type, sub_val); | 4113 | return sema.addConstant(child_type, sub_val); |
| ... | @@ -4010,11 +4137,11 @@ fn zirErrUnionPayload( | ... | @@ -4010,11 +4137,11 @@ fn zirErrUnionPayload( |
| 4010 | const operand_src = src; | 4137 | const operand_src = src; |
| 4011 | const operand_ty = sema.typeOf(operand); | 4138 | const operand_ty = sema.typeOf(operand); |
| 4012 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 4142 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 4016 | if (val.getError()) |name| { | 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 | const data = val.castTag(.eu_payload).?.data; | 4146 | const data = val.castTag(.eu_payload).?.data; |
| 4020 | const result_ty = operand_ty.errorUnionPayload(); | 4147 | const result_ty = operand_ty.errorUnionPayload(); |
| ... | @@ -4046,7 +4173,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -4046,7 +4173,7 @@ fn zirErrUnionPayloadPtr( |
| 4046 | assert(operand_ty.zigTypeTag() == .Pointer); | 4173 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4047 | | 4174 | |
| 4048 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) | 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 | const payload_ty = operand_ty.elemType().errorUnionPayload(); | 4178 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 4052 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ | 4179 | const operand_pointer_ty = try Type.ptr(sema.arena, .{ |
| ... | @@ -4058,7 +4185,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -4058,7 +4185,7 @@ fn zirErrUnionPayloadPtr( |
| 4058 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { | 4185 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 4059 | if (try pointer_val.pointerDeref(sema.arena)) |val| { | 4186 | if (try pointer_val.pointerDeref(sema.arena)) |val| { |
| 4060 | if (val.getError()) |name| { | 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 | return sema.addConstant( | 4190 | return sema.addConstant( |
| 4064 | operand_pointer_ty, | 4191 | operand_pointer_ty, |
| ... | @@ -4085,7 +4212,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi | ... | @@ -4085,7 +4212,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi |
| 4085 | const operand = sema.resolveInst(inst_data.operand); | 4212 | const operand = sema.resolveInst(inst_data.operand); |
| 4086 | const operand_ty = sema.typeOf(operand); | 4213 | const operand_ty = sema.typeOf(operand); |
| 4087 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | const result_ty = operand_ty.errorUnionSet(); | 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,7 +4237,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 4110 | assert(operand_ty.zigTypeTag() == .Pointer); | 4237 | assert(operand_ty.zigTypeTag() == .Pointer); |
| 4111 | | 4238 | |
| 4112 | if (operand_ty.elemType().zigTypeTag() != .ErrorUnion) | 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 | const result_ty = operand_ty.elemType().errorUnionSet(); | 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,9 +4261,9 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 4134 | const operand = sema.resolveInst(inst_data.operand); | 4261 | const operand = sema.resolveInst(inst_data.operand); |
| 4135 | const operand_ty = sema.typeOf(operand); | 4262 | const operand_ty = sema.typeOf(operand); |
| 4136 | if (operand_ty.zigTypeTag() != .ErrorUnion) | 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 | if (operand_ty.errorUnionPayload().zigTypeTag() != .Void) { | 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,7 +4404,7 @@ fn funcCommon( |
| 4277 | } | 4404 | } |
| 4278 | | 4405 | |
| 4279 | if (align_val.tag() != .null_value) { | 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 | is_generic = is_generic or bare_return_type.requiresComptime(); | 4410 | is_generic = is_generic or bare_return_type.requiresComptime(); |
| ... | @@ -4309,15 +4436,15 @@ fn funcCommon( | ... | @@ -4309,15 +4436,15 @@ fn funcCommon( |
| 4309 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; | 4436 | const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset }; |
| 4310 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); | 4437 | log.debug("extern fn symbol expected in lib '{s}'", .{lib_name}); |
| 4311 | mod.comp.stage1AddLinkLib(lib_name) catch |err| { | 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 | lib_name, @errorName(err), | 4440 | lib_name, @errorName(err), |
| 4314 | }); | 4441 | }); |
| 4315 | }; | 4442 | }; |
| 4316 | const target = mod.getTarget(); | 4443 | const target = mod.getTarget(); |
| 4317 | if (target_util.is_libc_lib_name(target, lib_name)) { | 4444 | if (target_util.is_libc_lib_name(target, lib_name)) { |
| 4318 | if (!mod.comp.bin_file.options.link_libc) { | 4445 | if (!mod.comp.bin_file.options.link_libc) { |
| 4319 | return mod.fail( | 4446 | return sema.fail( |
| 4320 | &block.base, | 4447 | block, |
| 4321 | lib_name_src, | 4448 | lib_name_src, |
| 4322 | "dependency on libc must be explicitly specified in the build command", | 4449 | "dependency on libc must be explicitly specified in the build command", |
| 4323 | .{}, | 4450 | .{}, |
| ... | @@ -4327,8 +4454,8 @@ fn funcCommon( | ... | @@ -4327,8 +4454,8 @@ fn funcCommon( |
| 4327 | } | 4454 | } |
| 4328 | if (target_util.is_libcpp_lib_name(target, lib_name)) { | 4455 | if (target_util.is_libcpp_lib_name(target, lib_name)) { |
| 4329 | if (!mod.comp.bin_file.options.link_libcpp) { | 4456 | if (!mod.comp.bin_file.options.link_libcpp) { |
| 4330 | return mod.fail( | 4457 | return sema.fail( |
| 4331 | &block.base, | 4458 | block, |
| 4332 | lib_name_src, | 4459 | lib_name_src, |
| 4333 | "dependency on libc++ must be explicitly specified in the build command", | 4460 | "dependency on libc++ must be explicitly specified in the build command", |
| 4334 | .{}, | 4461 | .{}, |
| ... | @@ -4337,8 +4464,8 @@ fn funcCommon( | ... | @@ -4337,8 +4464,8 @@ fn funcCommon( |
| 4337 | break :blk; | 4464 | break :blk; |
| 4338 | } | 4465 | } |
| 4339 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { | 4466 | if (!target.isWasm() and !mod.comp.bin_file.options.pic) { |
| 4340 | return mod.fail( | 4467 | return sema.fail( |
| 4341 | &block.base, | 4468 | block, |
| 4342 | lib_name_src, | 4469 | lib_name_src, |
| 4343 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", | 4470 | "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.", |
| 4344 | .{ lib_name, lib_name }, | 4471 | .{ lib_name, lib_name }, |
| ... | @@ -4528,7 +4655,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -4528,7 +4655,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 4528 | const ptr_ty = sema.typeOf(ptr); | 4655 | const ptr_ty = sema.typeOf(ptr); |
| 4529 | if (ptr_ty.zigTypeTag() != .Pointer) { | 4656 | if (ptr_ty.zigTypeTag() != .Pointer) { |
| 4530 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 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 | // TODO handle known-pointer-address | 4660 | // TODO handle known-pointer-address |
| 4534 | const src = inst_data.src(); | 4661 | const src = inst_data.src(); |
| ... | @@ -4639,7 +4766,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4639,7 +4766,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 4639 | if (try sema.isComptimeKnown(block, operand_src, operand)) { | 4766 | if (try sema.isComptimeKnown(block, operand_src, operand)) { |
| 4640 | return sema.coerce(block, dest_type, operand, operand_src); | 4767 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4641 | } else if (dest_is_comptime_int) { | 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 | try sema.requireRuntimeBlock(block, operand_src); | 4772 | try sema.requireRuntimeBlock(block, operand_src); |
| ... | @@ -4676,8 +4803,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4676,8 +4803,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4676 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { | 4803 | const dest_is_comptime_float = switch (dest_type.zigTypeTag()) { |
| 4677 | .ComptimeFloat => true, | 4804 | .ComptimeFloat => true, |
| 4678 | .Float => false, | 4805 | .Float => false, |
| 4679 | else => return sema.mod.fail( | 4806 | else => return sema.fail( |
| 4680 | &block.base, | 4807 | block, |
| 4681 | dest_ty_src, | 4808 | dest_ty_src, |
| 4682 | "expected float type, found '{}'", | 4809 | "expected float type, found '{}'", |
| 4683 | .{dest_type}, | 4810 | .{dest_type}, |
| ... | @@ -4687,8 +4814,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4687,8 +4814,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4687 | const operand_ty = sema.typeOf(operand); | 4814 | const operand_ty = sema.typeOf(operand); |
| 4688 | switch (operand_ty.zigTypeTag()) { | 4815 | switch (operand_ty.zigTypeTag()) { |
| 4689 | .ComptimeFloat, .Float, .ComptimeInt => {}, | 4816 | .ComptimeFloat, .Float, .ComptimeInt => {}, |
| 4690 | else => return sema.mod.fail( | 4817 | else => return sema.fail( |
| 4691 | &block.base, | 4818 | block, |
| 4692 | operand_src, | 4819 | operand_src, |
| 4693 | "expected float type, found '{}'", | 4820 | "expected float type, found '{}'", |
| 4694 | .{operand_ty}, | 4821 | .{operand_ty}, |
| ... | @@ -4699,7 +4826,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4699,7 +4826,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 4699 | return sema.coerce(block, dest_type, operand, operand_src); | 4826 | return sema.coerce(block, dest_type, operand, operand_src); |
| 4700 | } | 4827 | } |
| 4701 | if (dest_is_comptime_float) { | 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 | const target = sema.mod.getTarget(); | 4831 | const target = sema.mod.getTarget(); |
| 4705 | const src_bits = operand_ty.floatBits(target); | 4832 | const src_bits = operand_ty.floatBits(target); |
| ... | @@ -4817,7 +4944,7 @@ fn zirSwitchCapture( | ... | @@ -4817,7 +4944,7 @@ fn zirSwitchCapture( |
| 4817 | | 4944 | |
| 4818 | _ = is_ref; | 4945 | _ = is_ref; |
| 4819 | _ = is_multi; | 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 | fn zirSwitchCaptureElse( | 4950 | fn zirSwitchCaptureElse( |
| ... | @@ -4835,7 +4962,7 @@ fn zirSwitchCaptureElse( | ... | @@ -4835,7 +4962,7 @@ fn zirSwitchCaptureElse( |
| 4835 | const src = switch_info.src(); | 4962 | const src = switch_info.src(); |
| 4836 | | 4963 | |
| 4837 | _ = is_ref; | 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 | fn zirSwitchBlock( | 4968 | fn zirSwitchBlock( |
| ... | @@ -4916,7 +5043,6 @@ fn analyzeSwitch( | ... | @@ -4916,7 +5043,6 @@ fn analyzeSwitch( |
| 4916 | src_node_offset: i32, | 5043 | src_node_offset: i32, |
| 4917 | ) CompileError!Air.Inst.Ref { | 5044 | ) CompileError!Air.Inst.Ref { |
| 4918 | const gpa = sema.gpa; | 5045 | const gpa = sema.gpa; |
| 4919 | const mod = sema.mod; | | |
| 4920 | | 5046 | |
| 4921 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { | 5047 | const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) { |
| 4922 | .none => .{ .body = &.{}, .end = extra_end }, | 5048 | .none => .{ .body = &.{}, .end = extra_end }, |
| ... | @@ -4938,15 +5064,15 @@ fn analyzeSwitch( | ... | @@ -4938,15 +5064,15 @@ fn analyzeSwitch( |
| 4938 | // Validate usage of '_' prongs. | 5064 | // Validate usage of '_' prongs. |
| 4939 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { | 5065 | if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) { |
| 4940 | const msg = msg: { | 5066 | const msg = msg: { |
| 4941 | const msg = try mod.errMsg( | 5067 | const msg = try sema.errMsg( |
| 4942 | &block.base, | 5068 | block, |
| 4943 | src, | 5069 | src, |
| 4944 | "'_' prong only allowed when switching on non-exhaustive enums", | 5070 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 4945 | .{}, | 5071 | .{}, |
| 4946 | ); | 5072 | ); |
| 4947 | errdefer msg.destroy(gpa); | 5073 | errdefer msg.destroy(gpa); |
| 4948 | try mod.errNote( | 5074 | try sema.errNote( |
| 4949 | &block.base, | 5075 | block, |
| 4950 | special_prong_src, | 5076 | special_prong_src, |
| 4951 | msg, | 5077 | msg, |
| 4952 | "'_' prong here", | 5078 | "'_' prong here", |
| ... | @@ -4954,7 +5080,7 @@ fn analyzeSwitch( | ... | @@ -4954,7 +5080,7 @@ fn analyzeSwitch( |
| 4954 | ); | 5080 | ); |
| 4955 | break :msg msg; | 5081 | break :msg msg; |
| 4956 | }; | 5082 | }; |
| 4957 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5083 | return sema.failWithOwnedErrorMsg(msg); |
| 4958 | } | 5084 | } |
| 4959 | | 5085 | |
| 4960 | // Validate for duplicate items, missing else prong, and invalid range. | 5086 | // Validate for duplicate items, missing else prong, and invalid range. |
| ... | @@ -5017,8 +5143,8 @@ fn analyzeSwitch( | ... | @@ -5017,8 +5143,8 @@ fn analyzeSwitch( |
| 5017 | .none => { | 5143 | .none => { |
| 5018 | if (!all_tags_handled) { | 5144 | if (!all_tags_handled) { |
| 5019 | const msg = msg: { | 5145 | const msg = msg: { |
| 5020 | const msg = try mod.errMsg( | 5146 | const msg = try sema.errMsg( |
| 5021 | &block.base, | 5147 | block, |
| 5022 | src, | 5148 | src, |
| 5023 | "switch must handle all possibilities", | 5149 | "switch must handle all possibilities", |
| 5024 | .{}, | 5150 | .{}, |
| ... | @@ -5030,15 +5156,15 @@ fn analyzeSwitch( | ... | @@ -5030,15 +5156,15 @@ fn analyzeSwitch( |
| 5030 | const field_name = operand_ty.enumFieldName(i); | 5156 | const field_name = operand_ty.enumFieldName(i); |
| 5031 | | 5157 | |
| 5032 | // TODO have this point to the tag decl instead of here | 5158 | // TODO have this point to the tag decl instead of here |
| 5033 | try mod.errNote( | 5159 | try sema.errNote( |
| 5034 | &block.base, | 5160 | block, |
| 5035 | src, | 5161 | src, |
| 5036 | msg, | 5162 | msg, |
| 5037 | "unhandled enumeration value: '{s}'", | 5163 | "unhandled enumeration value: '{s}'", |
| 5038 | .{field_name}, | 5164 | .{field_name}, |
| 5039 | ); | 5165 | ); |
| 5040 | } | 5166 | } |
| 5041 | try mod.errNoteNonLazy( | 5167 | try sema.mod.errNoteNonLazy( |
| 5042 | operand_ty.declSrcLoc(), | 5168 | operand_ty.declSrcLoc(), |
| 5043 | msg, | 5169 | msg, |
| 5044 | "enum '{}' declared here", | 5170 | "enum '{}' declared here", |
| ... | @@ -5046,20 +5172,20 @@ fn analyzeSwitch( | ... | @@ -5046,20 +5172,20 @@ fn analyzeSwitch( |
| 5046 | ); | 5172 | ); |
| 5047 | break :msg msg; | 5173 | break :msg msg; |
| 5048 | }; | 5174 | }; |
| 5049 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5175 | return sema.failWithOwnedErrorMsg(msg); |
| 5050 | } | 5176 | } |
| 5051 | }, | 5177 | }, |
| 5052 | .under => { | 5178 | .under => { |
| 5053 | if (all_tags_handled) return mod.fail( | 5179 | if (all_tags_handled) return sema.fail( |
| 5054 | &block.base, | 5180 | block, |
| 5055 | special_prong_src, | 5181 | special_prong_src, |
| 5056 | "unreachable '_' prong; all cases already handled", | 5182 | "unreachable '_' prong; all cases already handled", |
| 5057 | .{}, | 5183 | .{}, |
| 5058 | ); | 5184 | ); |
| 5059 | }, | 5185 | }, |
| 5060 | .@"else" => { | 5186 | .@"else" => { |
| 5061 | if (all_tags_handled) return mod.fail( | 5187 | if (all_tags_handled) return sema.fail( |
| 5062 | &block.base, | 5188 | block, |
| 5063 | special_prong_src, | 5189 | special_prong_src, |
| 5064 | "unreachable else prong; all cases already handled", | 5190 | "unreachable else prong; all cases already handled", |
| 5065 | .{}, | 5191 | .{}, |
| ... | @@ -5068,8 +5194,8 @@ fn analyzeSwitch( | ... | @@ -5068,8 +5194,8 @@ fn analyzeSwitch( |
| 5068 | } | 5194 | } |
| 5069 | }, | 5195 | }, |
| 5070 | | 5196 | |
| 5071 | .ErrorSet => return mod.fail(&block.base, src, "TODO validate switch .ErrorSet", .{}), | 5197 | .ErrorSet => return sema.fail(block, src, "TODO validate switch .ErrorSet", .{}), |
| 5072 | .Union => return mod.fail(&block.base, src, "TODO validate switch .Union", .{}), | 5198 | .Union => return sema.fail(block, src, "TODO validate switch .Union", .{}), |
| 5073 | .Int, .ComptimeInt => { | 5199 | .Int, .ComptimeInt => { |
| 5074 | var range_set = RangeSet.init(gpa); | 5200 | var range_set = RangeSet.init(gpa); |
| 5075 | defer range_set.deinit(); | 5201 | defer range_set.deinit(); |
| ... | @@ -5144,12 +5270,13 @@ fn analyzeSwitch( | ... | @@ -5144,12 +5270,13 @@ fn analyzeSwitch( |
| 5144 | var arena = std.heap.ArenaAllocator.init(gpa); | 5270 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 5145 | defer arena.deinit(); | 5271 | defer arena.deinit(); |
| 5146 | | 5272 | |
| 5147 | const min_int = try operand_ty.minInt(&arena.allocator, mod.getTarget()); | 5273 | const target = sema.mod.getTarget(); |
| 5148 | const max_int = try operand_ty.maxInt(&arena.allocator, 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 | if (try range_set.spans(min_int, max_int, operand_ty)) { | 5276 | if (try range_set.spans(min_int, max_int, operand_ty)) { |
| 5150 | if (special_prong == .@"else") { | 5277 | if (special_prong == .@"else") { |
| 5151 | return mod.fail( | 5278 | return sema.fail( |
| 5152 | &block.base, | 5279 | block, |
| 5153 | special_prong_src, | 5280 | special_prong_src, |
| 5154 | "unreachable else prong; all cases already handled", | 5281 | "unreachable else prong; all cases already handled", |
| 5155 | .{}, | 5282 | .{}, |
| ... | @@ -5159,8 +5286,8 @@ fn analyzeSwitch( | ... | @@ -5159,8 +5286,8 @@ fn analyzeSwitch( |
| 5159 | } | 5286 | } |
| 5160 | } | 5287 | } |
| 5161 | if (special_prong != .@"else") { | 5288 | if (special_prong != .@"else") { |
| 5162 | return mod.fail( | 5289 | return sema.fail( |
| 5163 | &block.base, | 5290 | block, |
| 5164 | src, | 5291 | src, |
| 5165 | "switch must handle all possibilities", | 5292 | "switch must handle all possibilities", |
| 5166 | .{}, | 5293 | .{}, |
| ... | @@ -5221,8 +5348,8 @@ fn analyzeSwitch( | ... | @@ -5221,8 +5348,8 @@ fn analyzeSwitch( |
| 5221 | switch (special_prong) { | 5348 | switch (special_prong) { |
| 5222 | .@"else" => { | 5349 | .@"else" => { |
| 5223 | if (true_count + false_count == 2) { | 5350 | if (true_count + false_count == 2) { |
| 5224 | return mod.fail( | 5351 | return sema.fail( |
| 5225 | &block.base, | 5352 | block, |
| 5226 | src, | 5353 | src, |
| 5227 | "unreachable else prong; all cases already handled", | 5354 | "unreachable else prong; all cases already handled", |
| 5228 | .{}, | 5355 | .{}, |
| ... | @@ -5231,8 +5358,8 @@ fn analyzeSwitch( | ... | @@ -5231,8 +5358,8 @@ fn analyzeSwitch( |
| 5231 | }, | 5358 | }, |
| 5232 | .under, .none => { | 5359 | .under, .none => { |
| 5233 | if (true_count + false_count < 2) { | 5360 | if (true_count + false_count < 2) { |
| 5234 | return mod.fail( | 5361 | return sema.fail( |
| 5235 | &block.base, | 5362 | block, |
| 5236 | src, | 5363 | src, |
| 5237 | "switch must handle all possibilities", | 5364 | "switch must handle all possibilities", |
| 5238 | .{}, | 5365 | .{}, |
| ... | @@ -5243,8 +5370,8 @@ fn analyzeSwitch( | ... | @@ -5243,8 +5370,8 @@ fn analyzeSwitch( |
| 5243 | }, | 5370 | }, |
| 5244 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { | 5371 | .EnumLiteral, .Void, .Fn, .Pointer, .Type => { |
| 5245 | if (special_prong != .@"else") { | 5372 | if (special_prong != .@"else") { |
| 5246 | return mod.fail( | 5373 | return sema.fail( |
| 5247 | &block.base, | 5374 | block, |
| 5248 | src, | 5375 | src, |
| 5249 | "else prong required when switching on type '{}'", | 5376 | "else prong required when switching on type '{}'", |
| 5250 | .{operand_ty}, | 5377 | .{operand_ty}, |
| ... | @@ -5314,7 +5441,7 @@ fn analyzeSwitch( | ... | @@ -5314,7 +5441,7 @@ fn analyzeSwitch( |
| 5314 | .AnyFrame, | 5441 | .AnyFrame, |
| 5315 | .ComptimeFloat, | 5442 | .ComptimeFloat, |
| 5316 | .Float, | 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 | operand_ty, | 5445 | operand_ty, |
| 5319 | }), | 5446 | }), |
| 5320 | } | 5447 | } |
| ... | @@ -5707,19 +5834,18 @@ fn validateSwitchItemEnum( | ... | @@ -5707,19 +5834,18 @@ fn validateSwitchItemEnum( |
| 5707 | src_node_offset: i32, | 5834 | src_node_offset: i32, |
| 5708 | switch_prong_src: Module.SwitchProngSrc, | 5835 | switch_prong_src: Module.SwitchProngSrc, |
| 5709 | ) CompileError!void { | 5836 | ) CompileError!void { |
| 5710 | const mod = sema.mod; | | |
| 5711 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); | 5837 | const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 5712 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { | 5838 | const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse { |
| 5713 | const msg = msg: { | 5839 | const msg = msg: { |
| 5714 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); | 5840 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); |
| 5715 | const msg = try mod.errMsg( | 5841 | const msg = try sema.errMsg( |
| 5716 | &block.base, | 5842 | block, |
| 5717 | src, | 5843 | src, |
| 5718 | "enum '{}' has no tag with value '{}'", | 5844 | "enum '{}' has no tag with value '{}'", |
| 5719 | .{ item_tv.ty, item_tv.val }, | 5845 | .{ item_tv.ty, item_tv.val }, |
| 5720 | ); | 5846 | ); |
| 5721 | errdefer msg.destroy(sema.gpa); | 5847 | errdefer msg.destroy(sema.gpa); |
| 5722 | try mod.errNoteNonLazy( | 5848 | try sema.mod.errNoteNonLazy( |
| 5723 | item_tv.ty.declSrcLoc(), | 5849 | item_tv.ty.declSrcLoc(), |
| 5724 | msg, | 5850 | msg, |
| 5725 | "enum declared here", | 5851 | "enum declared here", |
| ... | @@ -5727,7 +5853,7 @@ fn validateSwitchItemEnum( | ... | @@ -5727,7 +5853,7 @@ fn validateSwitchItemEnum( |
| 5727 | ); | 5853 | ); |
| 5728 | break :msg msg; | 5854 | break :msg msg; |
| 5729 | }; | 5855 | }; |
| 5730 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5856 | return sema.failWithOwnedErrorMsg(msg); |
| 5731 | }; | 5857 | }; |
| 5732 | const maybe_prev_src = seen_fields[field_index]; | 5858 | const maybe_prev_src = seen_fields[field_index]; |
| 5733 | seen_fields[field_index] = switch_prong_src; | 5859 | seen_fields[field_index] = switch_prong_src; |
| ... | @@ -5742,20 +5868,19 @@ fn validateSwitchDupe( | ... | @@ -5742,20 +5868,19 @@ fn validateSwitchDupe( |
| 5742 | src_node_offset: i32, | 5868 | src_node_offset: i32, |
| 5743 | ) CompileError!void { | 5869 | ) CompileError!void { |
| 5744 | const prev_prong_src = maybe_prev_src orelse return; | 5870 | const prev_prong_src = maybe_prev_src orelse return; |
| 5745 | const mod = sema.mod; | | |
| 5746 | const gpa = sema.gpa; | 5871 | const gpa = sema.gpa; |
| 5747 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); | 5872 | const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5748 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); | 5873 | const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none); |
| 5749 | const msg = msg: { | 5874 | const msg = msg: { |
| 5750 | const msg = try mod.errMsg( | 5875 | const msg = try sema.errMsg( |
| 5751 | &block.base, | 5876 | block, |
| 5752 | src, | 5877 | src, |
| 5753 | "duplicate switch value", | 5878 | "duplicate switch value", |
| 5754 | .{}, | 5879 | .{}, |
| 5755 | ); | 5880 | ); |
| 5756 | errdefer msg.destroy(sema.gpa); | 5881 | errdefer msg.destroy(sema.gpa); |
| 5757 | try mod.errNote( | 5882 | try sema.errNote( |
| 5758 | &block.base, | 5883 | block, |
| 5759 | prev_src, | 5884 | prev_src, |
| 5760 | msg, | 5885 | msg, |
| 5761 | "previous value here", | 5886 | "previous value here", |
| ... | @@ -5763,7 +5888,7 @@ fn validateSwitchDupe( | ... | @@ -5763,7 +5888,7 @@ fn validateSwitchDupe( |
| 5763 | ); | 5888 | ); |
| 5764 | break :msg msg; | 5889 | break :msg msg; |
| 5765 | }; | 5890 | }; |
| 5766 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 5891 | return sema.failWithOwnedErrorMsg(msg); |
| 5767 | } | 5892 | } |
| 5768 | | 5893 | |
| 5769 | fn validateSwitchItemBool( | 5894 | fn validateSwitchItemBool( |
| ... | @@ -5783,7 +5908,7 @@ fn validateSwitchItemBool( | ... | @@ -5783,7 +5908,7 @@ fn validateSwitchItemBool( |
| 5783 | } | 5908 | } |
| 5784 | if (true_count.* + false_count.* > 2) { | 5909 | if (true_count.* + false_count.* > 2) { |
| 5785 | const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none); | 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,15 +5941,15 @@ fn validateSwitchNoRange( |
| 5816 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; | 5941 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; |
| 5817 | | 5942 | |
| 5818 | const msg = msg: { | 5943 | const msg = msg: { |
| 5819 | const msg = try sema.mod.errMsg( | 5944 | const msg = try sema.errMsg( |
| 5820 | &block.base, | 5945 | block, |
| 5821 | operand_src, | 5946 | operand_src, |
| 5822 | "ranges not allowed when switching on type '{}'", | 5947 | "ranges not allowed when switching on type '{}'", |
| 5823 | .{operand_ty}, | 5948 | .{operand_ty}, |
| 5824 | ); | 5949 | ); |
| 5825 | errdefer msg.destroy(sema.gpa); | 5950 | errdefer msg.destroy(sema.gpa); |
| 5826 | try sema.mod.errNote( | 5951 | try sema.errNote( |
| 5827 | &block.base, | 5952 | block, |
| 5828 | range_src, | 5953 | range_src, |
| 5829 | msg, | 5954 | msg, |
| 5830 | "range here", | 5955 | "range here", |
| ... | @@ -5832,7 +5957,7 @@ fn validateSwitchNoRange( | ... | @@ -5832,7 +5957,7 @@ fn validateSwitchNoRange( |
| 5832 | ); | 5957 | ); |
| 5833 | break :msg msg; | 5958 | break :msg msg; |
| 5834 | }; | 5959 | }; |
| 5835 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 5960 | return sema.failWithOwnedErrorMsg(msg); |
| 5836 | } | 5961 | } |
| 5837 | | 5962 | |
| 5838 | fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,7 +5966,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 5841 | _ = extra; | 5966 | _ = extra; |
| 5842 | const src = inst_data.src(); | 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 | fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,10 +5977,9 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 5852 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 5977 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 5853 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 5978 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 5854 | const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); | 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( | 5981 | const namespace = container_type.getNamespace() orelse return sema.fail( |
| 5858 | &block.base, | 5982 | block, |
| 5859 | lhs_src, | 5983 | lhs_src, |
| 5860 | "expected struct, enum, union, or opaque, found '{}'", | 5984 | "expected struct, enum, union, or opaque, found '{}'", |
| 5861 | .{container_type}, | 5985 | .{container_type}, |
| ... | @@ -5879,24 +6003,24 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5879,24 +6003,24 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 5879 | | 6003 | |
| 5880 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { | 6004 | const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) { |
| 5881 | error.ImportOutsidePkgPath => { | 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 | else => { | 6008 | else => { |
| 5885 | // TODO: these errors are file system errors; make sure an update() will | 6009 | // TODO: these errors are file system errors; make sure an update() will |
| 5886 | // retry this and not cache the file system error, which may be transient. | 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 | try mod.semaFile(result.file); | 6014 | try mod.semaFile(result.file); |
| 5891 | const file_root_decl = result.file.root_decl.?; | 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 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); | 6017 | return sema.addConstant(file_root_decl.ty, file_root_decl.val); |
| 5894 | } | 6018 | } |
| 5895 | | 6019 | |
| 5896 | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6020 | fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 5897 | _ = block; | 6021 | _ = block; |
| 5898 | _ = inst; | 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 | fn zirShl( | 6026 | fn zirShl( |
| ... | @@ -5933,8 +6057,8 @@ fn zirShl( | ... | @@ -5933,8 +6057,8 @@ fn zirShl( |
| 5933 | } | 6057 | } |
| 5934 | const val = try lhs_val.shl(rhs_val, sema.arena); | 6058 | const val = try lhs_val.shl(rhs_val, sema.arena); |
| 5935 | switch (air_tag) { | 6059 | switch (air_tag) { |
| 5936 | .shl_exact => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_exact", .{}), | 6060 | .shl_exact => return sema.fail(block, 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", .{}), | 6061 | .shl_sat => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_sat", .{}), |
| 5938 | .shl => {}, | 6062 | .shl => {}, |
| 5939 | else => unreachable, | 6063 | else => unreachable, |
| 5940 | } | 6064 | } |
| ... | @@ -6016,14 +6140,14 @@ fn zirBitwise( | ... | @@ -6016,14 +6140,14 @@ fn zirBitwise( |
| 6016 | | 6140 | |
| 6017 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { | 6141 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 6018 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), | 6144 | lhs_ty.arrayLen(), |
| 6021 | rhs_ty.arrayLen(), | 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 | } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) { | 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 | lhs_ty, | 6151 | lhs_ty, |
| 6028 | rhs_ty, | 6152 | rhs_ty, |
| 6029 | }); | 6153 | }); |
| ... | @@ -6032,7 +6156,7 @@ fn zirBitwise( | ... | @@ -6032,7 +6156,7 @@ fn zirBitwise( |
| 6032 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; | 6156 | const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt; |
| 6033 | | 6157 | |
| 6034 | if (!is_int) { | 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 | if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| { | 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,7 +6180,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 6056 | defer tracy.end(); | 6180 | defer tracy.end(); |
| 6057 | | 6181 | |
| 6058 | _ = inst; | 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 | fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,11 +6197,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6073 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 6197 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 6074 | | 6198 | |
| 6075 | const lhs_info = getArrayCatInfo(lhs_ty) orelse | 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 | const rhs_info = getArrayCatInfo(rhs_ty) orelse | 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 | if (!lhs_info.elem_type.eql(rhs_info.elem_type)) { | 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 | // When there is a sentinel mismatch, no sentinel on the result. The type system | 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,10 +6247,10 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6123 | else | 6247 | else |
| 6124 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); | 6248 | sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val)); |
| 6125 | } else { | 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 | } else { | 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,9 +6281,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6157 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known | 6281 | // In `**` rhs has to be comptime-known, but lhs can be runtime-known |
| 6158 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); | 6282 | const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize)); |
| 6159 | const mulinfo = getArrayCatInfo(lhs_ty) orelse | 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 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { | 6287 | if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| { |
| 6164 | var anon_decl = try block.startAnonDecl(); | 6288 | var anon_decl = try block.startAnonDecl(); |
| 6165 | defer anon_decl.deinit(); | 6289 | defer anon_decl.deinit(); |
| ... | @@ -6192,7 +6316,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6192,7 +6316,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6192 | return sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(final_ty, val)); | 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 | fn zirNegate( | 6322 | fn zirNegate( |
| ... | @@ -6245,7 +6369,7 @@ fn zirOverflowArithmetic( | ... | @@ -6245,7 +6369,7 @@ fn zirOverflowArithmetic( |
| 6245 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; | 6369 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; |
| 6246 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn analyzeArithmetic( | 6375 | fn analyzeArithmetic( |
| ... | @@ -6265,13 +6389,13 @@ fn analyzeArithmetic( | ... | @@ -6265,13 +6389,13 @@ fn analyzeArithmetic( |
| 6265 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); | 6389 | const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(); |
| 6266 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { | 6390 | if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) { |
| 6267 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), | 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 | } else if (lhs_zig_ty_tag == .Vector or rhs_zig_ty_tag == .Vector) { | 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 | lhs_ty, rhs_ty, | 6399 | lhs_ty, rhs_ty, |
| 6276 | }); | 6400 | }); |
| 6277 | } | 6401 | } |
| ... | @@ -6283,8 +6407,8 @@ fn analyzeArithmetic( | ... | @@ -6283,8 +6407,8 @@ fn analyzeArithmetic( |
| 6283 | const air_tag: Air.Inst.Tag = switch (zir_tag) { | 6407 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 6284 | .add => .ptr_add, | 6408 | .add => .ptr_add, |
| 6285 | .sub => .ptr_sub, | 6409 | .sub => .ptr_sub, |
| 6286 | else => return sema.mod.fail( | 6410 | else => return sema.fail( |
| 6287 | &block.base, | 6411 | block, |
| 6288 | op_src, | 6412 | op_src, |
| 6289 | "invalid pointer arithmetic operand: '{s}''", | 6413 | "invalid pointer arithmetic operand: '{s}''", |
| 6290 | .{@tagName(zir_tag)}, | 6414 | .{@tagName(zir_tag)}, |
| ... | @@ -6298,7 +6422,7 @@ fn analyzeArithmetic( | ... | @@ -6298,7 +6422,7 @@ fn analyzeArithmetic( |
| 6298 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { | 6422 | if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| { |
| 6299 | _ = lhs_val; | 6423 | _ = lhs_val; |
| 6300 | _ = rhs_val; | 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 | } else { | 6426 | } else { |
| 6303 | break :runtime_src rhs_src; | 6427 | break :runtime_src rhs_src; |
| 6304 | } | 6428 | } |
| ... | @@ -6329,7 +6453,7 @@ fn analyzeArithmetic( | ... | @@ -6329,7 +6453,7 @@ fn analyzeArithmetic( |
| 6329 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; | 6453 | const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat; |
| 6330 | | 6454 | |
| 6331 | if (!is_int and !(is_float and floatOpAllowed(zir_tag))) { | 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 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), | 6457 | @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag), |
| 6334 | }); | 6458 | }); |
| 6335 | } | 6459 | } |
| ... | @@ -6939,7 +7063,7 @@ fn zirAsm( | ... | @@ -6939,7 +7063,7 @@ fn zirAsm( |
| 6939 | const clobbers_len = @truncate(u5, extended.small >> 10); | 7063 | const clobbers_len = @truncate(u5, extended.small >> 10); |
| 6940 | | 7064 | |
| 6941 | if (outputs_len > 1) { | 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 | var extra_i = extra.end; | 7069 | var extra_i = extra.end; |
| ... | @@ -6954,7 +7078,7 @@ fn zirAsm( | ... | @@ -6954,7 +7078,7 @@ fn zirAsm( |
| 6954 | output_type_bits >>= 1; | 7078 | output_type_bits >>= 1; |
| 6955 | | 7079 | |
| 6956 | if (!is_type) { | 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 | const constraint = sema.code.nullTerminatedString(output.data.constraint); | 7084 | const constraint = sema.code.nullTerminatedString(output.data.constraint); |
| ... | @@ -7011,7 +7135,6 @@ fn zirCmpEq( | ... | @@ -7011,7 +7135,6 @@ fn zirCmpEq( |
| 7011 | const tracy = trace(@src()); | 7135 | const tracy = trace(@src()); |
| 7012 | defer tracy.end(); | 7136 | defer tracy.end(); |
| 7013 | | 7137 | |
| 7014 | const mod = sema.mod; | | |
| 7015 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 7138 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 7016 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 7139 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 7017 | const src: LazySrcLoc = inst_data.src(); | 7140 | const src: LazySrcLoc = inst_data.src(); |
| ... | @@ -7040,11 +7163,11 @@ fn zirCmpEq( | ... | @@ -7040,11 +7163,11 @@ fn zirCmpEq( |
| 7040 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); | 7163 | return sema.analyzeIsNull(block, src, opt_operand, op == .neq); |
| 7041 | } | 7164 | } |
| 7042 | if (((lhs_ty_tag == .Null and rhs_ty.isCPtr()) or (rhs_ty_tag == .Null and lhs_ty.isCPtr()))) { | 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 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { | 7168 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { |
| 7046 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; | 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 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { | 7172 | if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) { |
| 7050 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); | 7173 | return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op); |
| ... | @@ -7103,7 +7226,7 @@ fn analyzeCmpUnionTag( | ... | @@ -7103,7 +7226,7 @@ fn analyzeCmpUnionTag( |
| 7103 | const union_ty = sema.typeOf(un); | 7226 | const union_ty = sema.typeOf(un); |
| 7104 | const union_tag_ty = union_ty.unionTagType() orelse { | 7227 | const union_tag_ty = union_ty.unionTagType() orelse { |
| 7105 | // TODO note at declaration site that says "union foo is not tagged" | 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 | // Coerce both the union and the tag to the union's tag type, and then execute the | 7231 | // Coerce both the union and the tag to the union's tag type, and then execute the |
| 7109 | // enum comparison codepath. | 7232 | // enum comparison codepath. |
| ... | @@ -7155,7 +7278,7 @@ fn analyzeCmp( | ... | @@ -7155,7 +7278,7 @@ fn analyzeCmp( |
| 7155 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; | 7278 | const instructions = &[_]Air.Inst.Ref{ lhs, rhs }; |
| 7156 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); | 7279 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } }); |
| 7157 | if (!resolved_type.isSelfComparable(is_equality_cmp)) { | 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 | @tagName(op), resolved_type, | 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,7 +7375,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 7252 | .Null, | 7375 | .Null, |
| 7253 | .BoundFn, | 7376 | .BoundFn, |
| 7254 | .Opaque, | 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 | .Type, | 7379 | .Type, |
| 7257 | .EnumLiteral, | 7380 | .EnumLiteral, |
| 7258 | .ComptimeFloat, | 7381 | .ComptimeFloat, |
| ... | @@ -7340,7 +7463,7 @@ fn zirRetAddr( | ... | @@ -7340,7 +7463,7 @@ fn zirRetAddr( |
| 7340 | extended: Zir.Inst.Extended.InstData, | 7463 | extended: Zir.Inst.Extended.InstData, |
| 7341 | ) CompileError!Air.Inst.Ref { | 7464 | ) CompileError!Air.Inst.Ref { |
| 7342 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirBuiltinSrc( | 7469 | fn zirBuiltinSrc( |
| ... | @@ -7349,7 +7472,7 @@ fn zirBuiltinSrc( | ... | @@ -7349,7 +7472,7 @@ fn zirBuiltinSrc( |
| 7349 | extended: Zir.Inst.Extended.InstData, | 7472 | extended: Zir.Inst.Extended.InstData, |
| 7350 | ) CompileError!Air.Inst.Ref { | 7473 | ) CompileError!Air.Inst.Ref { |
| 7351 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,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 | @tagName(t), | 7678 | @tagName(t), |
| 7556 | }), | 7679 | }), |
| 7557 | } | 7680 | } |
| ... | @@ -7601,8 +7724,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) | ... | @@ -7601,8 +7724,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc) |
| 7601 | const res = try Module.makeIntType(sema.arena, .unsigned, count); | 7724 | const res = try Module.makeIntType(sema.arena, .unsigned, count); |
| 7602 | return sema.addType(res); | 7725 | return sema.addType(res); |
| 7603 | }, | 7726 | }, |
| 7604 | else => return sema.mod.fail( | 7727 | else => return sema.fail( |
| 7605 | &block.base, | 7728 | block, |
| 7606 | src, | 7729 | src, |
| 7607 | "bit shifting operation expected integer type, found '{}'", | 7730 | "bit shifting operation expected integer type, found '{}'", |
| 7608 | .{operand}, | 7731 | .{operand}, |
| ... | @@ -8026,7 +8149,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -8026,7 +8149,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8026 | } else 0; | 8149 | } else 0; |
| 8027 | | 8150 | |
| 8028 | if (bit_end != 0 and bit_start >= bit_end * 8) | 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 | const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type); | 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,11 +8182,10 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 8059 | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8182 | fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8060 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8183 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8061 | const src = inst_data.src(); | 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 | fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { | 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 | const gpa = sema.gpa; | 8189 | const gpa = sema.gpa; |
| 8068 | const zir_datas = sema.code.instructions.items(.data); | 8190 | const zir_datas = sema.code.instructions.items(.data); |
| 8069 | const inst_data = zir_datas[inst].pl_node; | 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,12 +8229,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8107 | const other_field_type_data = zir_datas[other_field_type].pl_node; | 8229 | const other_field_type_data = zir_datas[other_field_type].pl_node; |
| 8108 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; | 8230 | const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node }; |
| 8109 | const msg = msg: { | 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 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 8235 | break :msg msg; |
| 8114 | }; | 8236 | }; |
| 8115 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 8237 | return sema.failWithOwnedErrorMsg(msg); |
| 8116 | } | 8238 | } |
| 8117 | found_fields[field_index] = item.data.field_type; | 8239 | found_fields[field_index] = item.data.field_type; |
| 8118 | field_inits[field_index] = sema.resolveInst(item.data.init); | 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,9 +8252,9 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8130 | const template = "missing struct field: {s}"; | 8252 | const template = "missing struct field: {s}"; |
| 8131 | const args = .{field_name}; | 8253 | const args = .{field_name}; |
| 8132 | if (root_msg) |msg| { | 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 | } else { | 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 | } else { | 8259 | } else { |
| 8138 | field_inits[i] = try sema.addConstant(field.ty, field.default_val); | 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,17 +8263,17 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8141 | if (root_msg) |msg| { | 8263 | if (root_msg) |msg| { |
| 8142 | const fqn = try struct_obj.getFullyQualifiedName(gpa); | 8264 | const fqn = try struct_obj.getFullyQualifiedName(gpa); |
| 8143 | defer gpa.free(fqn); | 8265 | defer gpa.free(fqn); |
| 8144 | try mod.errNoteNonLazy( | 8266 | try sema.mod.errNoteNonLazy( |
| 8145 | struct_obj.srcLoc(), | 8267 | struct_obj.srcLoc(), |
| 8146 | msg, | 8268 | msg, |
| 8147 | "struct '{s}' declared here", | 8269 | "struct '{s}' declared here", |
| 8148 | .{fqn}, | 8270 | .{fqn}, |
| 8149 | ); | 8271 | ); |
| 8150 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 8272 | return sema.failWithOwnedErrorMsg(msg); |
| 8151 | } | 8273 | } |
| 8152 | | 8274 | |
| 8153 | if (is_ref) { | 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 | const is_comptime = for (field_inits) |field_init| { | 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,12 +8290,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8168 | return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values)); | 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 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { | 8294 | } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| { |
| 8173 | const union_obj = union_payload.data; | 8295 | const union_obj = union_payload.data; |
| 8174 | | 8296 | |
| 8175 | if (extra.data.fields_len != 1) { | 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 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); | 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,7 +8308,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: |
| 8186 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 8308 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); |
| 8187 | | 8309 | |
| 8188 | if (is_ref) { | 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 | const init_inst = sema.resolveInst(item.data.init); | 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,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 | unreachable; | 8326 | unreachable; |
| 8205 | } | 8327 | } |
| ... | @@ -8209,7 +8331,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ | ... | @@ -8209,7 +8331,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ |
| 8209 | const src = inst_data.src(); | 8331 | const src = inst_data.src(); |
| 8210 | | 8332 | |
| 8211 | _ = is_ref; | 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 | fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref { | 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,13 +8391,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r |
| 8269 | const src = inst_data.src(); | 8391 | const src = inst_data.src(); |
| 8270 | | 8392 | |
| 8271 | _ = is_ref; | 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 | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8397 | fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8276 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8398 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8277 | const src = inst_data.src(); | 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 | fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,7 +8420,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8298 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); | 8420 | return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name); |
| 8299 | return sema.addType(field.ty); | 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 | resolved_ty, | 8424 | resolved_ty, |
| 8303 | }), | 8425 | }), |
| 8304 | } | 8426 | } |
| ... | @@ -8310,7 +8432,7 @@ fn zirErrorReturnTrace( | ... | @@ -8310,7 +8432,7 @@ fn zirErrorReturnTrace( |
| 8310 | extended: Zir.Inst.Extended.InstData, | 8432 | extended: Zir.Inst.Extended.InstData, |
| 8311 | ) CompileError!Air.Inst.Ref { | 8433 | ) CompileError!Air.Inst.Ref { |
| 8312 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirFrame( | 8438 | fn zirFrame( |
| ... | @@ -8319,7 +8441,7 @@ fn zirFrame( | ... | @@ -8319,7 +8441,7 @@ fn zirFrame( |
| 8319 | extended: Zir.Inst.Extended.InstData, | 8441 | extended: Zir.Inst.Extended.InstData, |
| 8320 | ) CompileError!Air.Inst.Ref { | 8442 | ) CompileError!Air.Inst.Ref { |
| 8321 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirFrameAddress( | 8447 | fn zirFrameAddress( |
| ... | @@ -8328,7 +8450,7 @@ fn zirFrameAddress( | ... | @@ -8328,7 +8450,7 @@ fn zirFrameAddress( |
| 8328 | extended: Zir.Inst.Extended.InstData, | 8450 | extended: Zir.Inst.Extended.InstData, |
| 8329 | ) CompileError!Air.Inst.Ref { | 8451 | ) CompileError!Air.Inst.Ref { |
| 8330 | const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) }; | 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 | fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,25 +8477,25 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 8355 | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8477 | fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8356 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8478 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8357 | const src = inst_data.src(); | 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 | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8483 | fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8362 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8484 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8363 | const src = inst_data.src(); | 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 | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8489 | fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8368 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8490 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8369 | const src = inst_data.src(); | 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 | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8495 | fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8374 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8496 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8375 | const src = inst_data.src(); | 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 | fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,25 +8528,25 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8406 | }; | 8528 | }; |
| 8407 | return sema.addType(ty); | 8529 | return sema.addType(ty); |
| 8408 | }, | 8530 | }, |
| 8409 | .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}), | 8531 | .Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}), |
| 8410 | .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}), | 8532 | .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}), |
| 8411 | .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}), | 8533 | .Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}), |
| 8412 | .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}), | 8534 | .Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}), |
| 8413 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, | 8535 | .ComptimeFloat => return Air.Inst.Ref.comptime_float_type, |
| 8414 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, | 8536 | .ComptimeInt => return Air.Inst.Ref.comptime_int_type, |
| 8415 | .Undefined => return Air.Inst.Ref.undefined_type, | 8537 | .Undefined => return Air.Inst.Ref.undefined_type, |
| 8416 | .Null => return Air.Inst.Ref.null_type, | 8538 | .Null => return Air.Inst.Ref.null_type, |
| 8417 | .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}), | 8539 | .Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}), |
| 8418 | .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}), | 8540 | .ErrorUnion => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorUnion", .{}), |
| 8419 | .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}), | 8541 | .ErrorSet => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorSet", .{}), |
| 8420 | .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}), | 8542 | .Enum => return sema.fail(block, src, "TODO: Sema.zirReify for Enum", .{}), |
| 8421 | .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}), | 8543 | .Union => return sema.fail(block, src, "TODO: Sema.zirReify for Union", .{}), |
| 8422 | .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}), | 8544 | .Fn => return sema.fail(block, src, "TODO: Sema.zirReify for Fn", .{}), |
| 8423 | .BoundFn => @panic("TODO delete BoundFn from the language"), | 8545 | .BoundFn => @panic("TODO delete BoundFn from the language"), |
| 8424 | .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}), | 8546 | .Opaque => return sema.fail(block, src, "TODO: Sema.zirReify for Opaque", .{}), |
| 8425 | .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}), | 8547 | .Frame => return sema.fail(block, src, "TODO: Sema.zirReify for Frame", .{}), |
| 8426 | .AnyFrame => return Air.Inst.Ref.anyframe_type, | 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 | .EnumLiteral => return Air.Inst.Ref.enum_literal_type, | 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,26 +8554,26 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 8432 | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8554 | fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8433 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8555 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8434 | const src = inst_data.src(); | 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 | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8560 | fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8439 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8561 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8440 | const src = inst_data.src(); | 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 | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8566 | fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8445 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8567 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8446 | const src = inst_data.src(); | 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 | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8572 | fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8451 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8573 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8452 | const src = inst_data.src(); | 8574 | const src = inst_data.src(); |
| 8453 | // TODO don't forget the safety check! | 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 | fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,15 +8611,15 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8489 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8611 | const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 8490 | const type_res = try sema.resolveType(block, src, extra.lhs); | 8612 | const type_res = try sema.resolveType(block, src, extra.lhs); |
| 8491 | if (type_res.zigTypeTag() != .Pointer) | 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 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); | 8615 | const ptr_align = type_res.ptrAlignment(sema.mod.getTarget()); |
| 8494 | | 8616 | |
| 8495 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { | 8617 | if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| { |
| 8496 | const addr = val.toUnsignedInt(); | 8618 | const addr = val.toUnsignedInt(); |
| 8497 | if (!type_res.isAllowzeroPtr() and addr == 0) | 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 | if (addr != 0 and addr % ptr_align != 0) | 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 | const val_payload = try sema.arena.create(Value.Payload.U64); | 8624 | const val_payload = try sema.arena.create(Value.Payload.U64); |
| 8503 | val_payload.* = .{ | 8625 | val_payload.* = .{ |
| ... | @@ -8535,7 +8657,7 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8535,7 +8657,7 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8535 | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8657 | fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8536 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8658 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8537 | const src = inst_data.src(); | 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 | fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,12 +8669,12 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr |
| 8547 | const operand = sema.resolveInst(extra.rhs); | 8669 | const operand = sema.resolveInst(extra.rhs); |
| 8548 | const operand_ty = sema.typeOf(operand); | 8670 | const operand_ty = sema.typeOf(operand); |
| 8549 | if (operand_ty.zigTypeTag() != .Pointer) { | 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 | @tagName(operand_ty.zigTypeTag()), operand_ty, | 8673 | @tagName(operand_ty.zigTypeTag()), operand_ty, |
| 8552 | }); | 8674 | }); |
| 8553 | } | 8675 | } |
| 8554 | if (dest_ty.zigTypeTag() != .Pointer) { | 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 | @tagName(dest_ty.zigTypeTag()), dest_ty, | 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,7 +8693,6 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8571 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); | 8693 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 8572 | const operand = sema.resolveInst(extra.rhs); | 8694 | const operand = sema.resolveInst(extra.rhs); |
| 8573 | const operand_ty = sema.typeOf(operand); | 8695 | const operand_ty = sema.typeOf(operand); |
| 8574 | const mod = sema.mod; | | |
| 8575 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); | 8696 | const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty); |
| 8576 | const src_is_comptime_int = try sema.checkIntType(block, operand_src, operand_ty); | 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,7 +8700,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8579 | return sema.coerce(block, dest_ty, operand, operand_src); | 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 | const src_info = operand_ty.intInfo(target); | 8704 | const src_info = operand_ty.intInfo(target); |
| 8584 | const dest_info = dest_ty.intInfo(target); | 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,28 +8710,28 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8589 | | 8710 | |
| 8590 | if (!src_is_comptime_int) { | 8711 | if (!src_is_comptime_int) { |
| 8591 | if (src_info.signedness != dest_info.signedness) { | 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 | @tagName(dest_info.signedness), operand_ty, | 8714 | @tagName(dest_info.signedness), operand_ty, |
| 8594 | }); | 8715 | }); |
| 8595 | } | 8716 | } |
| 8596 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { | 8717 | if (src_info.bits > 0 and src_info.bits < dest_info.bits) { |
| 8597 | const msg = msg: { | 8718 | const msg = msg: { |
| 8598 | const msg = try mod.errMsg( | 8719 | const msg = try sema.errMsg( |
| 8599 | &block.base, | 8720 | block, |
| 8600 | src, | 8721 | src, |
| 8601 | "destination type '{}' has more bits than source type '{}'", | 8722 | "destination type '{}' has more bits than source type '{}'", |
| 8602 | .{ dest_ty, operand_ty }, | 8723 | .{ dest_ty, operand_ty }, |
| 8603 | ); | 8724 | ); |
| 8604 | errdefer msg.destroy(mod.gpa); | 8725 | errdefer msg.destroy(sema.gpa); |
| 8605 | try mod.errNote(&block.base, dest_ty_src, msg, "destination type has {d} bits", .{ | 8726 | try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{ |
| 8606 | dest_info.bits, | 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 | src_info.bits, | 8730 | src_info.bits, |
| 8610 | }); | 8731 | }); |
| 8611 | break :msg msg; | 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,7 +8747,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 8626 | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8747 | fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8627 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8748 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8628 | const src = inst_data.src(); | 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 | fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,7 +8758,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8637 | const operand_ty = sema.typeOf(operand); | 8758 | const operand_ty = sema.typeOf(operand); |
| 8638 | // TODO implement support for vectors | 8759 | // TODO implement support for vectors |
| 8639 | if (operand_ty.zigTypeTag() != .Int) { | 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 | operand_ty, | 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,7 +8785,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8664 | const operand_ty = sema.typeOf(operand); | 8785 | const operand_ty = sema.typeOf(operand); |
| 8665 | // TODO implement support for vectors | 8786 | // TODO implement support for vectors |
| 8666 | if (operand_ty.zigTypeTag() != .Int) { | 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 | operand_ty, | 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,7 +8797,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8676 | | 8797 | |
| 8677 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | 8798 | const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 8678 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 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 | } else operand_src; | 8801 | } else operand_src; |
| 8681 | | 8802 | |
| 8682 | try sema.requireRuntimeBlock(block, runtime_src); | 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,55 +8807,55 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A |
| 8686 | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8807 | fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8687 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8808 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8688 | const src = inst_data.src(); | 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 | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8813 | fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8693 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8814 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8694 | const src = inst_data.src(); | 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 | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8819 | fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8699 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 8820 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 8700 | const src = inst_data.src(); | 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 | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8825 | fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8705 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8826 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8706 | const src = inst_data.src(); | 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 | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8831 | fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8711 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8832 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8712 | const src = inst_data.src(); | 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 | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8837 | fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8717 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8838 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8718 | const src = inst_data.src(); | 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 | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8843 | fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8723 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8844 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8724 | const src = inst_data.src(); | 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 | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8849 | fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8729 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8850 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8730 | const src = inst_data.src(); | 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 | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8855 | fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8735 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8856 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8736 | const src = inst_data.src(); | 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 | /// Returns `true` if the type was a comptime_int. | 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,7 +8863,7 @@ fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) Com |
| 8742 | switch (ty.zigTypeTag()) { | 8863 | switch (ty.zigTypeTag()) { |
| 8743 | .ComptimeInt => return true, | 8864 | .ComptimeInt => return true, |
| 8744 | .Int => return false, | 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,7 +8875,7 @@ fn checkFloatType( |
| 8754 | ) CompileError!void { | 8875 | ) CompileError!void { |
| 8755 | switch (ty.zigTypeTag()) { | 8876 | switch (ty.zigTypeTag()) { |
| 8756 | .ComptimeFloat, .Float => {}, | 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 | ty, | 8879 | ty, |
| 8759 | }), | 8880 | }), |
| 8760 | } | 8881 | } |
| ... | @@ -8775,8 +8896,8 @@ fn checkAtomicOperandType( | ... | @@ -8775,8 +8896,8 @@ fn checkAtomicOperandType( |
| 8775 | .Float => { | 8896 | .Float => { |
| 8776 | const bit_count = ty.floatBits(target); | 8897 | const bit_count = ty.floatBits(target); |
| 8777 | if (bit_count > max_atomic_bits) { | 8898 | if (bit_count > max_atomic_bits) { |
| 8778 | return sema.mod.fail( | 8899 | return sema.fail( |
| 8779 | &block.base, | 8900 | block, |
| 8780 | ty_src, | 8901 | ty_src, |
| 8781 | "expected {d}-bit float type or smaller; found {d}-bit float type", | 8902 | "expected {d}-bit float type or smaller; found {d}-bit float type", |
| 8782 | .{ max_atomic_bits, bit_count }, | 8903 | .{ max_atomic_bits, bit_count }, |
| ... | @@ -8788,8 +8909,8 @@ fn checkAtomicOperandType( | ... | @@ -8788,8 +8909,8 @@ fn checkAtomicOperandType( |
| 8788 | else => { | 8909 | else => { |
| 8789 | if (ty.isPtrAtRuntime()) return; | 8910 | if (ty.isPtrAtRuntime()) return; |
| 8790 | | 8911 | |
| 8791 | return sema.mod.fail( | 8912 | return sema.fail( |
| 8792 | &block.base, | 8913 | block, |
| 8793 | ty_src, | 8914 | ty_src, |
| 8794 | "expected bool, integer, float, enum, or pointer type; found {}", | 8915 | "expected bool, integer, float, enum, or pointer type; found {}", |
| 8795 | .{ty}, | 8916 | .{ty}, |
| ... | @@ -8798,8 +8919,8 @@ fn checkAtomicOperandType( | ... | @@ -8798,8 +8919,8 @@ fn checkAtomicOperandType( |
| 8798 | }; | 8919 | }; |
| 8799 | const bit_count = int_ty.intInfo(target).bits; | 8920 | const bit_count = int_ty.intInfo(target).bits; |
| 8800 | if (bit_count > max_atomic_bits) { | 8921 | if (bit_count > max_atomic_bits) { |
| 8801 | return sema.mod.fail( | 8922 | return sema.fail( |
| 8802 | &block.base, | 8923 | block, |
| 8803 | ty_src, | 8924 | ty_src, |
| 8804 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", | 8925 | "expected {d}-bit integer type or smaller; found {d}-bit integer type", |
| 8805 | .{ max_atomic_bits, bit_count }, | 8926 | .{ max_atomic_bits, bit_count }, |
| ... | @@ -8823,7 +8944,7 @@ fn resolveExportOptions( | ... | @@ -8823,7 +8944,7 @@ fn resolveExportOptions( |
| 8823 | const linkage_index = struct_obj.fields.getIndex("linkage").?; | 8944 | const linkage_index = struct_obj.fields.getIndex("linkage").?; |
| 8824 | const section_index = struct_obj.fields.getIndex("section").?; | 8945 | const section_index = struct_obj.fields.getIndex("section").?; |
| 8825 | if (!fields[section_index].isNull()) { | 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 | return std.builtin.ExportOptions{ | 8949 | return std.builtin.ExportOptions{ |
| 8829 | .name = try fields[name_index].toAllocatedBytes(sema.arena), | 8950 | .name = try fields[name_index].toAllocatedBytes(sema.arena), |
| ... | @@ -8864,7 +8985,6 @@ fn zirCmpxchg( | ... | @@ -8864,7 +8985,6 @@ fn zirCmpxchg( |
| 8864 | inst: Zir.Inst.Index, | 8985 | inst: Zir.Inst.Index, |
| 8865 | air_tag: Air.Inst.Tag, | 8986 | air_tag: Air.Inst.Tag, |
| 8866 | ) CompileError!Air.Inst.Ref { | 8987 | ) CompileError!Air.Inst.Ref { |
| 8867 | const mod = sema.mod; | | |
| 8868 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 8988 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8869 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; | 8989 | const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data; |
| 8870 | const src = inst_data.src(); | 8990 | const src = inst_data.src(); |
| ... | @@ -8880,8 +9000,8 @@ fn zirCmpxchg( | ... | @@ -8880,8 +9000,8 @@ fn zirCmpxchg( |
| 8880 | const elem_ty = sema.typeOf(ptr).elemType(); | 9000 | const elem_ty = sema.typeOf(ptr).elemType(); |
| 8881 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); | 9001 | try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty); |
| 8882 | if (elem_ty.zigTypeTag() == .Float) { | 9002 | if (elem_ty.zigTypeTag() == .Float) { |
| 8883 | return mod.fail( | 9003 | return sema.fail( |
| 8884 | &block.base, | 9004 | block, |
| 8885 | elem_ty_src, | 9005 | elem_ty_src, |
| 8886 | "expected bool, integer, enum, or pointer type; found '{}'", | 9006 | "expected bool, integer, enum, or pointer type; found '{}'", |
| 8887 | .{elem_ty}, | 9007 | .{elem_ty}, |
| ... | @@ -8893,16 +9013,16 @@ fn zirCmpxchg( | ... | @@ -8893,16 +9013,16 @@ fn zirCmpxchg( |
| 8893 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); | 9013 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order); |
| 8894 | | 9014 | |
| 8895 | if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { | 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 | if (@enumToInt(failure_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) { | 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 | if (@enumToInt(failure_order) > @enumToInt(success_order)) { | 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 | if (failure_order == .Release or failure_order == .AcqRel) { | 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 | const result_ty = try Module.optionalType(sema.arena, elem_ty); | 9028 | const result_ty = try Module.optionalType(sema.arena, elem_ty); |
| ... | @@ -8952,25 +9072,25 @@ fn zirCmpxchg( | ... | @@ -8952,25 +9072,25 @@ fn zirCmpxchg( |
| 8952 | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9072 | fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8953 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9073 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8954 | const src = inst_data.src(); | 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 | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9078 | fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8959 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9079 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8960 | const src = inst_data.src(); | 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 | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9084 | fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8965 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9085 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8966 | const src = inst_data.src(); | 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 | fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9090 | fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8971 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9091 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 8972 | const src = inst_data.src(); | 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 | fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 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,8 +9108,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 8988 | | 9108 | |
| 8989 | switch (order) { | 9109 | switch (order) { |
| 8990 | .Release, .AcqRel => { | 9110 | .Release, .AcqRel => { |
| 8991 | return sema.mod.fail( | 9111 | return sema.fail( |
| 8992 | &block.base, | 9112 | block, |
| 8993 | order_src, | 9113 | order_src, |
| 8994 | "@atomicLoad atomic ordering must not be Release or AcqRel", | 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,7 +9139,6 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile |
| 9019 | } | 9139 | } |
| 9020 | | 9140 | |
| 9021 | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9141 | fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9022 | const mod = sema.mod; | | |
| 9023 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9142 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9024 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 9143 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 9025 | const src = inst_data.src(); | 9144 | const src = inst_data.src(); |
| ... | @@ -9037,14 +9156,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -9037,14 +9156,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9037 | | 9156 | |
| 9038 | switch (operand_ty.zigTypeTag()) { | 9157 | switch (operand_ty.zigTypeTag()) { |
| 9039 | .Enum => if (op != .Xchg) { | 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 | .Bool => if (op != .Xchg) { | 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 | .Float => switch (op) { | 9164 | .Float => switch (op) { |
| 9046 | .Xchg, .Add, .Sub => {}, | 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 | else => {}, | 9168 | else => {}, |
| 9050 | } | 9169 | } |
| ... | @@ -9052,7 +9171,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE | ... | @@ -9052,7 +9171,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE |
| 9052 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); | 9171 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering); |
| 9053 | | 9172 | |
| 9054 | if (order == .Unordered) { | 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 | // special case zero bit types | 9177 | // special case zero bit types |
| ... | @@ -9115,8 +9234,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil | ... | @@ -9115,8 +9234,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9115 | | 9234 | |
| 9116 | const air_tag: Air.Inst.Tag = switch (order) { | 9235 | const air_tag: Air.Inst.Tag = switch (order) { |
| 9117 | .Acquire, .AcqRel => { | 9236 | .Acquire, .AcqRel => { |
| 9118 | return sema.mod.fail( | 9237 | return sema.fail( |
| 9119 | &block.base, | 9238 | block, |
| 9120 | order_src, | 9239 | order_src, |
| 9121 | "@atomicStore atomic ordering must not be Acquire or AcqRel", | 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,31 +9253,31 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil |
| 9134 | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9253 | fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9135 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9254 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9136 | const src = inst_data.src(); | 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 | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9259 | fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9141 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9260 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9142 | const src = inst_data.src(); | 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 | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9265 | fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9147 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9266 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9148 | const src = inst_data.src(); | 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 | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9271 | fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9153 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9272 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9154 | const src = inst_data.src(); | 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 | fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9277 | fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9159 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9278 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9160 | const src = inst_data.src(); | 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 | fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void { | 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,16 +9291,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9172 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 9291 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9173 | | 9292 | |
| 9174 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { | 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 | if (dest_ptr_ty.isConstPtr()) { | 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 | const uncasted_src_ptr = sema.resolveInst(extra.source); | 9300 | const uncasted_src_ptr = sema.resolveInst(extra.source); |
| 9182 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); | 9301 | const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr); |
| 9183 | if (uncasted_src_ptr_ty.zigTypeTag() != .Pointer) { | 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 | uncasted_src_ptr_ty, | 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,7 +9327,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9208 | _ = dest_ptr_val; | 9327 | _ = dest_ptr_val; |
| 9209 | _ = src_ptr_val; | 9328 | _ = src_ptr_val; |
| 9210 | _ = len_val; | 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 | } else break :rs len_src; | 9331 | } else break :rs len_src; |
| 9213 | } else break :rs src_src; | 9332 | } else break :rs src_src; |
| 9214 | } else dest_src; | 9333 | } else dest_src; |
| ... | @@ -9236,10 +9355,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -9236,10 +9355,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9236 | const dest_ptr = sema.resolveInst(extra.dest); | 9355 | const dest_ptr = sema.resolveInst(extra.dest); |
| 9237 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 9356 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 9238 | if (dest_ptr_ty.zigTypeTag() != .Pointer) { | 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 | if (dest_ptr_ty.isConstPtr()) { | 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 | const elem_ty = dest_ptr_ty.elemType2(); | 9363 | const elem_ty = dest_ptr_ty.elemType2(); |
| 9245 | const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src); | 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,7 +9373,7 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9254 | _ = ptr_val; | 9373 | _ = ptr_val; |
| 9255 | _ = len_val; | 9374 | _ = len_val; |
| 9256 | _ = val; | 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 | } else break :rs value_src; | 9377 | } else break :rs value_src; |
| 9259 | } else break :rs len_src; | 9378 | } else break :rs len_src; |
| 9260 | } else dest_src; | 9379 | } else dest_src; |
| ... | @@ -9275,19 +9394,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -9275,19 +9394,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro |
| 9275 | fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9394 | fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9276 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9395 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9277 | const src = inst_data.src(); | 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 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9400 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9282 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | 9401 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; |
| 9283 | const src = inst_data.src(); | 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 | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 9406 | fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 9288 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | 9407 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9289 | const src = inst_data.src(); | 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 | fn zirAwait( | 9412 | fn zirAwait( |
| ... | @@ -9300,7 +9419,7 @@ fn zirAwait( | ... | @@ -9300,7 +9419,7 @@ fn zirAwait( |
| 9300 | const src = inst_data.src(); | 9419 | const src = inst_data.src(); |
| 9301 | | 9420 | |
| 9302 | _ = is_nosuspend; | 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 | fn zirVarExtended( | 9425 | fn zirVarExtended( |
| ... | @@ -9360,7 +9479,7 @@ fn zirVarExtended( | ... | @@ -9360,7 +9479,7 @@ fn zirVarExtended( |
| 9360 | if (lib_name != null) { | 9479 | if (lib_name != null) { |
| 9361 | // Look at the sema code for functions which has this logic, it just needs to | 9480 | // Look at the sema code for functions which has this logic, it just needs to |
| 9362 | // be extracted and shared by both var and func | 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 | const new_var = try sema.gpa.create(Module.Var); | 9485 | const new_var = try sema.gpa.create(Module.Var); |
| ... | @@ -9496,7 +9615,7 @@ fn zirWasmMemorySize( | ... | @@ -9496,7 +9615,7 @@ fn zirWasmMemorySize( |
| 9496 | ) CompileError!Air.Inst.Ref { | 9615 | ) CompileError!Air.Inst.Ref { |
| 9497 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 9616 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 9498 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn zirWasmMemoryGrow( | 9621 | fn zirWasmMemoryGrow( |
| ... | @@ -9506,7 +9625,7 @@ fn zirWasmMemoryGrow( | ... | @@ -9506,7 +9625,7 @@ fn zirWasmMemoryGrow( |
| 9506 | ) CompileError!Air.Inst.Ref { | 9625 | ) CompileError!Air.Inst.Ref { |
| 9507 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 9626 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9508 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn zirBuiltinExtern( | 9631 | fn zirBuiltinExtern( |
| ... | @@ -9516,12 +9635,12 @@ fn zirBuiltinExtern( | ... | @@ -9516,12 +9635,12 @@ fn zirBuiltinExtern( |
| 9516 | ) CompileError!Air.Inst.Ref { | 9635 | ) CompileError!Air.Inst.Ref { |
| 9517 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 9636 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 9518 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | 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 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { | 9641 | fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9523 | if (sema.func == null) { | 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,7 +9698,7 @@ fn validateVarType( |
| 9579 | }, | 9698 | }, |
| 9580 | } else unreachable; // TODO should not need else unreachable | 9699 | } else unreachable; // TODO should not need else unreachable |
| 9581 | if (!ok) { | 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,7 +9803,7 @@ fn panicWithMsg( |
| 9684 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); | 9803 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 9685 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ | 9804 | const ptr_stack_trace_ty = try Type.ptr(arena, .{ |
| 9686 | .pointee_type = stack_trace_ty, | 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 | const null_stack_trace = try sema.addConstant( | 9808 | const null_stack_trace = try sema.addConstant( |
| 9690 | try Module.optionalType(arena, ptr_stack_trace_ty), | 9809 | try Module.optionalType(arena, ptr_stack_trace_ty), |
| ... | @@ -9730,7 +9849,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { | ... | @@ -9730,7 +9849,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void { |
| 9730 | sema.branch_count += 1; | 9849 | sema.branch_count += 1; |
| 9731 | if (sema.branch_count > sema.branch_quota) { | 9850 | if (sema.branch_count > sema.branch_quota) { |
| 9732 | // TODO show the "called from here" stack | 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,7 +9864,6 @@ fn fieldVal( |
| 9745 | // When editing this function, note that there is corresponding logic to be edited | 9864 | // When editing this function, note that there is corresponding logic to be edited |
| 9746 | // in `fieldPtr`. This function takes a value and returns a value. | 9865 | // in `fieldPtr`. This function takes a value and returns a value. |
| 9747 | | 9866 | |
| 9748 | const mod = sema.mod; | | |
| 9749 | const arena = sema.arena; | 9867 | const arena = sema.arena; |
| 9750 | const object_src = src; // TODO better source location | 9868 | const object_src = src; // TODO better source location |
| 9751 | const object_ty = sema.typeOf(object); | 9869 | const object_ty = sema.typeOf(object); |
| ... | @@ -9758,8 +9876,8 @@ fn fieldVal( | ... | @@ -9758,8 +9876,8 @@ fn fieldVal( |
| 9758 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), | 9876 | try Value.Tag.int_u64.create(arena, object_ty.arrayLen()), |
| 9759 | ); | 9877 | ); |
| 9760 | } else { | 9878 | } else { |
| 9761 | return mod.fail( | 9879 | return sema.fail( |
| 9762 | &block.base, | 9880 | block, |
| 9763 | field_name_src, | 9881 | field_name_src, |
| 9764 | "no member named '{s}' in '{}'", | 9882 | "no member named '{s}' in '{}'", |
| 9765 | .{ field_name, object_ty }, | 9883 | .{ field_name, object_ty }, |
| ... | @@ -9773,8 +9891,8 @@ fn fieldVal( | ... | @@ -9773,8 +9891,8 @@ fn fieldVal( |
| 9773 | const result_ty = object_ty.slicePtrFieldType(buf); | 9891 | const result_ty = object_ty.slicePtrFieldType(buf); |
| 9774 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { | 9892 | if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| { |
| 9775 | if (val.isUndef()) return sema.addConstUndef(result_ty); | 9893 | if (val.isUndef()) return sema.addConstUndef(result_ty); |
| 9776 | return mod.fail( | 9894 | return sema.fail( |
| 9777 | &block.base, | 9895 | block, |
| 9778 | field_name_src, | 9896 | field_name_src, |
| 9779 | "TODO implement comptime slice ptr", | 9897 | "TODO implement comptime slice ptr", |
| 9780 | .{}, | 9898 | .{}, |
| ... | @@ -9794,8 +9912,8 @@ fn fieldVal( | ... | @@ -9794,8 +9912,8 @@ fn fieldVal( |
| 9794 | try sema.requireRuntimeBlock(block, src); | 9912 | try sema.requireRuntimeBlock(block, src); |
| 9795 | return block.addTyOp(.slice_len, result_ty, object); | 9913 | return block.addTyOp(.slice_len, result_ty, object); |
| 9796 | } else { | 9914 | } else { |
| 9797 | return mod.fail( | 9915 | return sema.fail( |
| 9798 | &block.base, | 9916 | block, |
| 9799 | field_name_src, | 9917 | field_name_src, |
| 9800 | "no member named '{s}' in '{}'", | 9918 | "no member named '{s}' in '{}'", |
| 9801 | .{ field_name, object_ty }, | 9919 | .{ field_name, object_ty }, |
| ... | @@ -9812,8 +9930,8 @@ fn fieldVal( | ... | @@ -9812,8 +9930,8 @@ fn fieldVal( |
| 9812 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), | 9930 | try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()), |
| 9813 | ); | 9931 | ); |
| 9814 | } else { | 9932 | } else { |
| 9815 | return mod.fail( | 9933 | return sema.fail( |
| 9816 | &block.base, | 9934 | block, |
| 9817 | field_name_src, | 9935 | field_name_src, |
| 9818 | "no member named '{s}' in '{}'", | 9936 | "no member named '{s}' in '{}'", |
| 9819 | .{ field_name, object_ty }, | 9937 | .{ field_name, object_ty }, |
| ... | @@ -9850,10 +9968,10 @@ fn fieldVal( | ... | @@ -9850,10 +9968,10 @@ fn fieldVal( |
| 9850 | break :blk name; | 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 | field_name, child_type, | 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 | return sema.addConstant( | 9976 | return sema.addConstant( |
| 9859 | try child_type.copy(arena), | 9977 | try child_type.copy(arena), |
| ... | @@ -9873,7 +9991,7 @@ fn fieldVal( | ... | @@ -9873,7 +9991,7 @@ fn fieldVal( |
| 9873 | .Union => "union", | 9991 | .Union => "union", |
| 9874 | else => unreachable, | 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 | kw_name, child_type, field_name, | 9995 | kw_name, child_type, field_name, |
| 9878 | }); | 9996 | }); |
| 9879 | }, | 9997 | }, |
| ... | @@ -9885,14 +10003,14 @@ fn fieldVal( | ... | @@ -9885,14 +10003,14 @@ fn fieldVal( |
| 9885 | } | 10003 | } |
| 9886 | const field_index = child_type.enumFieldIndex(field_name) orelse { | 10004 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 9887 | const msg = msg: { | 10005 | const msg = msg: { |
| 9888 | const msg = try mod.errMsg( | 10006 | const msg = try sema.errMsg( |
| 9889 | &block.base, | 10007 | block, |
| 9890 | src, | 10008 | src, |
| 9891 | "enum '{}' has no member named '{s}'", | 10009 | "enum '{}' has no member named '{s}'", |
| 9892 | .{ child_type, field_name }, | 10010 | .{ child_type, field_name }, |
| 9893 | ); | 10011 | ); |
| 9894 | errdefer msg.destroy(sema.gpa); | 10012 | errdefer msg.destroy(sema.gpa); |
| 9895 | try mod.errNoteNonLazy( | 10013 | try sema.mod.errNoteNonLazy( |
| 9896 | child_type.declSrcLoc(), | 10014 | child_type.declSrcLoc(), |
| 9897 | msg, | 10015 | msg, |
| 9898 | "enum declared here", | 10016 | "enum declared here", |
| ... | @@ -9900,20 +10018,20 @@ fn fieldVal( | ... | @@ -9900,20 +10018,20 @@ fn fieldVal( |
| 9900 | ); | 10018 | ); |
| 9901 | break :msg msg; | 10019 | break :msg msg; |
| 9902 | }; | 10020 | }; |
| 9903 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10021 | return sema.failWithOwnedErrorMsg(msg); |
| 9904 | }; | 10022 | }; |
| 9905 | const field_index_u32 = @intCast(u32, field_index); | 10023 | const field_index_u32 = @intCast(u32, field_index); |
| 9906 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); | 10024 | const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32); |
| 9907 | return sema.addConstant(try child_type.copy(arena), enum_val); | 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 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), | 10030 | .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9913 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), | 10031 | .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty), |
| 9914 | else => {}, | 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 | fn fieldPtr( | 10037 | fn fieldPtr( |
| ... | @@ -9927,12 +10045,11 @@ fn fieldPtr( | ... | @@ -9927,12 +10045,11 @@ fn fieldPtr( |
| 9927 | // When editing this function, note that there is corresponding logic to be edited | 10045 | // When editing this function, note that there is corresponding logic to be edited |
| 9928 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 10046 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 9929 | | 10047 | |
| 9930 | const mod = sema.mod; | | |
| 9931 | const object_ptr_src = src; // TODO better source location | 10048 | const object_ptr_src = src; // TODO better source location |
| 9932 | const object_ptr_ty = sema.typeOf(object_ptr); | 10049 | const object_ptr_ty = sema.typeOf(object_ptr); |
| 9933 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { | 10050 | const object_ty = switch (object_ptr_ty.zigTypeTag()) { |
| 9934 | .Pointer => object_ptr_ty.elemType(), | 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 | switch (object_ty.zigTypeTag()) { | 10054 | switch (object_ty.zigTypeTag()) { |
| 9938 | .Array => { | 10055 | .Array => { |
| ... | @@ -9944,8 +10061,8 @@ fn fieldPtr( | ... | @@ -9944,8 +10061,8 @@ fn fieldPtr( |
| 9944 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), | 10061 | try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()), |
| 9945 | )); | 10062 | )); |
| 9946 | } else { | 10063 | } else { |
| 9947 | return mod.fail( | 10064 | return sema.fail( |
| 9948 | &block.base, | 10065 | block, |
| 9949 | field_name_src, | 10066 | field_name_src, |
| 9950 | "no member named '{s}' in '{}'", | 10067 | "no member named '{s}' in '{}'", |
| 9951 | .{ field_name, object_ty }, | 10068 | .{ field_name, object_ty }, |
| ... | @@ -9962,22 +10079,22 @@ fn fieldPtr( | ... | @@ -9962,22 +10079,22 @@ fn fieldPtr( |
| 9962 | // the runtime value to it, and then return the `alloc`. | 10079 | // the runtime value to it, and then return the `alloc`. |
| 9963 | // In both cases the pointer should be const. | 10080 | // In both cases the pointer should be const. |
| 9964 | if (mem.eql(u8, field_name, "ptr")) { | 10081 | if (mem.eql(u8, field_name, "ptr")) { |
| 9965 | return mod.fail( | 10082 | return sema.fail( |
| 9966 | &block.base, | 10083 | block, |
| 9967 | field_name_src, | 10084 | field_name_src, |
| 9968 | "TODO: implement reference to 'ptr' field of slice '{}'", | 10085 | "TODO: implement reference to 'ptr' field of slice '{}'", |
| 9969 | .{object_ty}, | 10086 | .{object_ty}, |
| 9970 | ); | 10087 | ); |
| 9971 | } else if (mem.eql(u8, field_name, "len")) { | 10088 | } else if (mem.eql(u8, field_name, "len")) { |
| 9972 | return mod.fail( | 10089 | return sema.fail( |
| 9973 | &block.base, | 10090 | block, |
| 9974 | field_name_src, | 10091 | field_name_src, |
| 9975 | "TODO: implement reference to 'len' field of slice '{}'", | 10092 | "TODO: implement reference to 'len' field of slice '{}'", |
| 9976 | .{object_ty}, | 10093 | .{object_ty}, |
| 9977 | ); | 10094 | ); |
| 9978 | } else { | 10095 | } else { |
| 9979 | return mod.fail( | 10096 | return sema.fail( |
| 9980 | &block.base, | 10097 | block, |
| 9981 | field_name_src, | 10098 | field_name_src, |
| 9982 | "no member named '{s}' in '{}'", | 10099 | "no member named '{s}' in '{}'", |
| 9983 | .{ field_name, object_ty }, | 10100 | .{ field_name, object_ty }, |
| ... | @@ -9996,8 +10113,8 @@ fn fieldPtr( | ... | @@ -9996,8 +10113,8 @@ fn fieldPtr( |
| 9996 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), | 10113 | try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()), |
| 9997 | )); | 10114 | )); |
| 9998 | } else { | 10115 | } else { |
| 9999 | return mod.fail( | 10116 | return sema.fail( |
| 10000 | &block.base, | 10117 | block, |
| 10001 | field_name_src, | 10118 | field_name_src, |
| 10002 | "no member named '{s}' in '{}'", | 10119 | "no member named '{s}' in '{}'", |
| 10003 | .{ field_name, object_ty }, | 10120 | .{ field_name, object_ty }, |
| ... | @@ -10036,10 +10153,10 @@ fn fieldPtr( | ... | @@ -10036,10 +10153,10 @@ fn fieldPtr( |
| 10036 | break :blk name; | 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 | field_name, child_type, | 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 | var anon_decl = try block.startAnonDecl(); | 10161 | var anon_decl = try block.startAnonDecl(); |
| 10045 | defer anon_decl.deinit(); | 10162 | defer anon_decl.deinit(); |
| ... | @@ -10061,7 +10178,7 @@ fn fieldPtr( | ... | @@ -10061,7 +10178,7 @@ fn fieldPtr( |
| 10061 | .Union => "union", | 10178 | .Union => "union", |
| 10062 | else => unreachable, | 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 | kw_name, child_type, field_name, | 10182 | kw_name, child_type, field_name, |
| 10066 | }); | 10183 | }); |
| 10067 | }, | 10184 | }, |
| ... | @@ -10073,14 +10190,14 @@ fn fieldPtr( | ... | @@ -10073,14 +10190,14 @@ fn fieldPtr( |
| 10073 | } | 10190 | } |
| 10074 | const field_index = child_type.enumFieldIndex(field_name) orelse { | 10191 | const field_index = child_type.enumFieldIndex(field_name) orelse { |
| 10075 | const msg = msg: { | 10192 | const msg = msg: { |
| 10076 | const msg = try mod.errMsg( | 10193 | const msg = try sema.errMsg( |
| 10077 | &block.base, | 10194 | block, |
| 10078 | src, | 10195 | src, |
| 10079 | "enum '{}' has no member named '{s}'", | 10196 | "enum '{}' has no member named '{s}'", |
| 10080 | .{ child_type, field_name }, | 10197 | .{ child_type, field_name }, |
| 10081 | ); | 10198 | ); |
| 10082 | errdefer msg.destroy(sema.gpa); | 10199 | errdefer msg.destroy(sema.gpa); |
| 10083 | try mod.errNoteNonLazy( | 10200 | try sema.mod.errNoteNonLazy( |
| 10084 | child_type.declSrcLoc(), | 10201 | child_type.declSrcLoc(), |
| 10085 | msg, | 10202 | msg, |
| 10086 | "enum declared here", | 10203 | "enum declared here", |
| ... | @@ -10088,7 +10205,7 @@ fn fieldPtr( | ... | @@ -10088,7 +10205,7 @@ fn fieldPtr( |
| 10088 | ); | 10205 | ); |
| 10089 | break :msg msg; | 10206 | break :msg msg; |
| 10090 | }; | 10207 | }; |
| 10091 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10208 | return sema.failWithOwnedErrorMsg(msg); |
| 10092 | }; | 10209 | }; |
| 10093 | const field_index_u32 = @intCast(u32, field_index); | 10210 | const field_index_u32 = @intCast(u32, field_index); |
| 10094 | var anon_decl = try block.startAnonDecl(); | 10211 | var anon_decl = try block.startAnonDecl(); |
| ... | @@ -10098,14 +10215,14 @@ fn fieldPtr( | ... | @@ -10098,14 +10215,14 @@ fn fieldPtr( |
| 10098 | try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32), | 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 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), | 10221 | .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10105 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), | 10222 | .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty), |
| 10106 | else => {}, | 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 | fn fieldCallBind( | 10228 | fn fieldCallBind( |
| ... | @@ -10119,13 +10236,12 @@ fn fieldCallBind( | ... | @@ -10119,13 +10236,12 @@ fn fieldCallBind( |
| 10119 | // When editing this function, note that there is corresponding logic to be edited | 10236 | // When editing this function, note that there is corresponding logic to be edited |
| 10120 | // in `fieldVal`. This function takes a pointer and returns a pointer. | 10237 | // in `fieldVal`. This function takes a pointer and returns a pointer. |
| 10121 | | 10238 | |
| 10122 | const mod = sema.mod; | | |
| 10123 | const raw_ptr_src = src; // TODO better source location | 10239 | const raw_ptr_src = src; // TODO better source location |
| 10124 | const raw_ptr_ty = sema.typeOf(raw_ptr); | 10240 | const raw_ptr_ty = sema.typeOf(raw_ptr); |
| 10125 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) | 10241 | const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One) |
| 10126 | raw_ptr_ty.childType() | 10242 | raw_ptr_ty.childType() |
| 10127 | else | 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 | // Optionally dereference a second pointer to get the concrete type. | 10246 | // Optionally dereference a second pointer to get the concrete type. |
| 10131 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; | 10247 | const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One; |
| ... | @@ -10194,7 +10310,7 @@ fn fieldCallBind( | ... | @@ -10194,7 +10310,7 @@ fn fieldCallBind( |
| 10194 | }; | 10310 | }; |
| 10195 | return sema.analyzeLoad(block, src, ptr_inst, src); | 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 | .Type => { | 10314 | .Type => { |
| 10199 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); | 10315 | const namespace = try sema.analyzeLoad(block, src, object_ptr, src); |
| 10200 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); | 10316 | return sema.fieldVal(block, src, namespace, field_name, field_name_src); |
| ... | @@ -10247,7 +10363,7 @@ fn fieldCallBind( | ... | @@ -10247,7 +10363,7 @@ fn fieldCallBind( |
| 10247 | else => {}, | 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 | fn namespaceLookup( | 10369 | fn namespaceLookup( |
| ... | @@ -10257,19 +10373,18 @@ fn namespaceLookup( | ... | @@ -10257,19 +10373,18 @@ fn namespaceLookup( |
| 10257 | namespace: *Scope.Namespace, | 10373 | namespace: *Scope.Namespace, |
| 10258 | decl_name: []const u8, | 10374 | decl_name: []const u8, |
| 10259 | ) CompileError!?*Decl { | 10375 | ) CompileError!?*Decl { |
| 10260 | const mod = sema.mod; | | |
| 10261 | const gpa = sema.gpa; | 10376 | const gpa = sema.gpa; |
| 10262 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { | 10377 | if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { |
| 10263 | if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) { | 10378 | if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) { |
| 10264 | const msg = msg: { | 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 | decl_name, | 10381 | decl_name, |
| 10267 | }); | 10382 | }); |
| 10268 | errdefer msg.destroy(gpa); | 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 | break :msg msg; | 10385 | break :msg msg; |
| 10271 | }; | 10386 | }; |
| 10272 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10387 | return sema.failWithOwnedErrorMsg(msg); |
| 10273 | } | 10388 | } |
| 10274 | return decl; | 10389 | return decl; |
| 10275 | } | 10390 | } |
| ... | @@ -10435,7 +10550,7 @@ fn unionFieldVal( | ... | @@ -10435,7 +10550,7 @@ fn unionFieldVal( |
| 10435 | } | 10550 | } |
| 10436 | | 10551 | |
| 10437 | try sema.requireRuntimeBlock(block, src); | 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 | fn elemPtr( | 10556 | fn elemPtr( |
| ... | @@ -10450,10 +10565,10 @@ fn elemPtr( | ... | @@ -10450,10 +10565,10 @@ fn elemPtr( |
| 10450 | const array_ptr_ty = sema.typeOf(array_ptr); | 10565 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 10451 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { | 10566 | const array_ty = switch (array_ptr_ty.zigTypeTag()) { |
| 10452 | .Pointer => array_ptr_ty.elemType(), | 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 | if (!array_ty.isIndexable()) { | 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 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { | 10573 | if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) { |
| 10459 | // we have to deref the ptr operand to get the actual array pointer | 10574 | // we have to deref the ptr operand to get the actual array pointer |
| ... | @@ -10464,7 +10579,7 @@ fn elemPtr( | ... | @@ -10464,7 +10579,7 @@ fn elemPtr( |
| 10464 | return sema.elemPtrArray(block, src, array_ptr, elem_index, elem_index_src); | 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 | fn elemVal( | 10585 | fn elemVal( |
| ... | @@ -10482,7 +10597,7 @@ fn elemVal( | ... | @@ -10482,7 +10597,7 @@ fn elemVal( |
| 10482 | .Slice => { | 10597 | .Slice => { |
| 10483 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { | 10598 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| { |
| 10484 | _ = slice_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10602 | try sema.requireRuntimeBlock(block, src); |
| 10488 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); | 10603 | return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index); |
| ... | @@ -10490,7 +10605,7 @@ fn elemVal( | ... | @@ -10490,7 +10605,7 @@ fn elemVal( |
| 10490 | .Many, .C => { | 10605 | .Many, .C => { |
| 10491 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { | 10606 | if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| { |
| 10492 | _ = ptr_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10610 | try sema.requireRuntimeBlock(block, src); |
| 10496 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); | 10611 | return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index); |
| ... | @@ -10505,7 +10620,7 @@ fn elemVal( | ... | @@ -10505,7 +10620,7 @@ fn elemVal( |
| 10505 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); | 10620 | const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10506 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { | 10621 | if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| { |
| 10507 | _ = slice_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10625 | try sema.requireRuntimeBlock(block, src); |
| 10511 | return block.addBinOp(.slice_elem_val, slice, elem_index); | 10626 | return block.addBinOp(.slice_elem_val, slice, elem_index); |
| ... | @@ -10519,7 +10634,7 @@ fn elemVal( | ... | @@ -10519,7 +10634,7 @@ fn elemVal( |
| 10519 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); | 10634 | const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src); |
| 10520 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { | 10635 | if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| { |
| 10521 | _ = ptr_val; | 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 | try sema.requireRuntimeBlock(block, src); | 10639 | try sema.requireRuntimeBlock(block, src); |
| 10525 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); | 10640 | return block.addBinOp(.ptr_elem_val, ptr, elem_index); |
| ... | @@ -10527,8 +10642,8 @@ fn elemVal( | ... | @@ -10527,8 +10642,8 @@ fn elemVal( |
| 10527 | try sema.requireRuntimeBlock(block, src); | 10642 | try sema.requireRuntimeBlock(block, src); |
| 10528 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); | 10643 | return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index); |
| 10529 | }, | 10644 | }, |
| 10530 | .One => return sema.mod.fail( | 10645 | .One => return sema.fail( |
| 10531 | &block.base, | 10646 | block, |
| 10532 | array_ptr_src, | 10647 | array_ptr_src, |
| 10533 | "expected pointer, found '{}'", | 10648 | "expected pointer, found '{}'", |
| 10534 | .{indexable_ty.elemType()}, | 10649 | .{indexable_ty.elemType()}, |
| ... | @@ -10538,8 +10653,8 @@ fn elemVal( | ... | @@ -10538,8 +10653,8 @@ fn elemVal( |
| 10538 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); | 10653 | const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src); |
| 10539 | return sema.analyzeLoad(block, src, ptr, elem_index_src); | 10654 | return sema.analyzeLoad(block, src, ptr, elem_index_src); |
| 10540 | }, | 10655 | }, |
| 10541 | else => return sema.mod.fail( | 10656 | else => return sema.fail( |
| 10542 | &block.base, | 10657 | block, |
| 10543 | array_ptr_src, | 10658 | array_ptr_src, |
| 10544 | "expected pointer, found '{}'", | 10659 | "expected pointer, found '{}'", |
| 10545 | .{indexable_ty}, | 10660 | .{indexable_ty}, |
| ... | @@ -10547,8 +10662,8 @@ fn elemVal( | ... | @@ -10547,8 +10662,8 @@ fn elemVal( |
| 10547 | } | 10662 | } |
| 10548 | }, | 10663 | }, |
| 10549 | }, | 10664 | }, |
| 10550 | else => return sema.mod.fail( | 10665 | else => return sema.fail( |
| 10551 | &block.base, | 10666 | block, |
| 10552 | array_ptr_src, | 10667 | array_ptr_src, |
| 10553 | "expected pointer, found '{}'", | 10668 | "expected pointer, found '{}'", |
| 10554 | .{maybe_ptr_ty}, | 10669 | .{maybe_ptr_ty}, |
| ... | @@ -10616,10 +10731,10 @@ fn coerce( | ... | @@ -10616,10 +10731,10 @@ fn coerce( |
| 10616 | if (dest_type.eql(inst_ty)) | 10731 | if (dest_type.eql(inst_ty)) |
| 10617 | return inst; | 10732 | return inst; |
| 10618 | | 10733 | |
| 10619 | const mod = sema.mod; | | |
| 10620 | const arena = sema.arena; | 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 | if (in_memory_result == .ok) { | 10738 | if (in_memory_result == .ok) { |
| 10624 | return sema.bitcast(block, dest_type, inst, inst_src); | 10739 | return sema.bitcast(block, dest_type, inst, inst_src); |
| 10625 | } | 10740 | } |
| ... | @@ -10636,8 +10751,6 @@ fn coerce( | ... | @@ -10636,8 +10751,6 @@ fn coerce( |
| 10636 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| | 10751 | if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some| |
| 10637 | return some; | 10752 | return some; |
| 10638 | | 10753 | |
| 10639 | const target = mod.getTarget(); | | |
| 10640 | | | |
| 10641 | switch (dest_type.zigTypeTag()) { | 10754 | switch (dest_type.zigTypeTag()) { |
| 10642 | .Optional => { | 10755 | .Optional => { |
| 10643 | // null to ?T | 10756 | // null to ?T |
| ... | @@ -10664,7 +10777,7 @@ fn coerce( | ... | @@ -10664,7 +10777,7 @@ fn coerce( |
| 10664 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; | 10777 | if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr; |
| 10665 | | 10778 | |
| 10666 | const dst_elem_type = dest_type.elemType(); | 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 | .ok => {}, | 10781 | .ok => {}, |
| 10669 | .no_match => break :src_array_ptr, | 10782 | .no_match => break :src_array_ptr, |
| 10670 | } | 10783 | } |
| ... | @@ -10733,14 +10846,14 @@ fn coerce( | ... | @@ -10733,14 +10846,14 @@ fn coerce( |
| 10733 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); | 10846 | const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type); |
| 10734 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { | 10847 | const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse { |
| 10735 | const msg = msg: { | 10848 | const msg = msg: { |
| 10736 | const msg = try mod.errMsg( | 10849 | const msg = try sema.errMsg( |
| 10737 | &block.base, | 10850 | block, |
| 10738 | inst_src, | 10851 | inst_src, |
| 10739 | "enum '{}' has no field named '{s}'", | 10852 | "enum '{}' has no field named '{s}'", |
| 10740 | .{ resolved_dest_type, bytes }, | 10853 | .{ resolved_dest_type, bytes }, |
| 10741 | ); | 10854 | ); |
| 10742 | errdefer msg.destroy(sema.gpa); | 10855 | errdefer msg.destroy(sema.gpa); |
| 10743 | try mod.errNoteNonLazy( | 10856 | try sema.mod.errNoteNonLazy( |
| 10744 | resolved_dest_type.declSrcLoc(), | 10857 | resolved_dest_type.declSrcLoc(), |
| 10745 | msg, | 10858 | msg, |
| 10746 | "enum declared here", | 10859 | "enum declared here", |
| ... | @@ -10748,7 +10861,7 @@ fn coerce( | ... | @@ -10748,7 +10861,7 @@ fn coerce( |
| 10748 | ); | 10861 | ); |
| 10749 | break :msg msg; | 10862 | break :msg msg; |
| 10750 | }; | 10863 | }; |
| 10751 | return mod.failWithOwnedErrorMsg(&block.base, msg); | 10864 | return sema.failWithOwnedErrorMsg(msg); |
| 10752 | }; | 10865 | }; |
| 10753 | return sema.addConstant( | 10866 | return sema.addConstant( |
| 10754 | resolved_dest_type, | 10867 | resolved_dest_type, |
| ... | @@ -10771,7 +10884,7 @@ fn coerce( | ... | @@ -10771,7 +10884,7 @@ fn coerce( |
| 10771 | else => {}, | 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 | const InMemoryCoercionResult = enum { | 10890 | const InMemoryCoercionResult = enum { |
| ... | @@ -10888,13 +11001,13 @@ fn coerceNum( | ... | @@ -10888,13 +11001,13 @@ fn coerceNum( |
| 10888 | .ComptimeInt, .Int => switch (src_zig_tag) { | 11001 | .ComptimeInt, .Int => switch (src_zig_tag) { |
| 10889 | .Float, .ComptimeFloat => { | 11002 | .Float, .ComptimeFloat => { |
| 10890 | if (val.floatHasFraction()) { | 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 | .Int, .ComptimeInt => { | 11008 | .Int, .ComptimeInt => { |
| 10896 | if (!val.intFitsInType(dest_type, target)) { | 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 | return try sema.addConstant(dest_type, val); | 11012 | return try sema.addConstant(dest_type, val); |
| 10900 | }, | 11013 | }, |
| ... | @@ -10908,8 +11021,8 @@ fn coerceNum( | ... | @@ -10908,8 +11021,8 @@ fn coerceNum( |
| 10908 | .Float => { | 11021 | .Float => { |
| 10909 | const result_val = try val.floatCast(sema.arena, dest_type); | 11022 | const result_val = try val.floatCast(sema.arena, dest_type); |
| 10910 | if (!val.eql(result_val, dest_type)) { | 11023 | if (!val.eql(result_val, dest_type)) { |
| 10911 | return sema.mod.fail( | 11024 | return sema.fail( |
| 10912 | &block.base, | 11025 | block, |
| 10913 | inst_src, | 11026 | inst_src, |
| 10914 | "type {} cannot represent float value {}", | 11027 | "type {} cannot represent float value {}", |
| 10915 | .{ dest_type, val }, | 11028 | .{ dest_type, val }, |
| ... | @@ -10922,8 +11035,8 @@ fn coerceNum( | ... | @@ -10922,8 +11035,8 @@ fn coerceNum( |
| 10922 | // TODO implement this compile error | 11035 | // TODO implement this compile error |
| 10923 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); | 11036 | //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty); |
| 10924 | //if (!int_again_val.eql(val, inst_ty)) { | 11037 | //if (!int_again_val.eql(val, inst_ty)) { |
| 10925 | // return sema.mod.fail( | 11038 | // return sema.fail( |
| 10926 | // &block.base, | 11039 | // block, |
| 10927 | // inst_src, | 11040 | // inst_src, |
| 10928 | // "type {} cannot represent integer value {}", | 11041 | // "type {} cannot represent integer value {}", |
| 10929 | // .{ dest_type, val }, | 11042 | // .{ dest_type, val }, |
| ... | @@ -10946,7 +11059,7 @@ fn coerceVarArgParam( | ... | @@ -10946,7 +11059,7 @@ fn coerceVarArgParam( |
| 10946 | ) !Air.Inst.Ref { | 11059 | ) !Air.Inst.Ref { |
| 10947 | const inst_ty = sema.typeOf(inst); | 11060 | const inst_ty = sema.typeOf(inst); |
| 10948 | switch (inst_ty.zigTypeTag()) { | 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 | else => {}, | 11063 | else => {}, |
| 10951 | } | 11064 | } |
| 10952 | // TODO implement more of this function. | 11065 | // TODO implement more of this function. |
| ... | @@ -10960,7 +11073,7 @@ fn storePtr( | ... | @@ -10960,7 +11073,7 @@ fn storePtr( |
| 10960 | src: LazySrcLoc, | 11073 | src: LazySrcLoc, |
| 10961 | ptr: Air.Inst.Ref, | 11074 | ptr: Air.Inst.Ref, |
| 10962 | uncasted_operand: Air.Inst.Ref, | 11075 | uncasted_operand: Air.Inst.Ref, |
| 10963 | ) !void { | 11076 | ) CompileError!void { |
| 10964 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); | 11077 | return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store); |
| 10965 | } | 11078 | } |
| 10966 | | 11079 | |
| ... | @@ -10976,7 +11089,7 @@ fn storePtr2( | ... | @@ -10976,7 +11089,7 @@ fn storePtr2( |
| 10976 | ) !void { | 11089 | ) !void { |
| 10977 | const ptr_ty = sema.typeOf(ptr); | 11090 | const ptr_ty = sema.typeOf(ptr); |
| 10978 | if (ptr_ty.isConstPtr()) | 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 | const elem_ty = ptr_ty.elemType(); | 11094 | const elem_ty = ptr_ty.elemType(); |
| 10982 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); | 11095 | const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); |
| ... | @@ -10985,7 +11098,7 @@ fn storePtr2( | ... | @@ -10985,7 +11098,7 @@ fn storePtr2( |
| 10985 | | 11098 | |
| 10986 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { | 11099 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 10987 | const operand_val = (try sema.resolveMaybeUndefVal(block, operand_src, operand)) orelse | 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 | if (ptr_val.tag() == .decl_ref_mut) { | 11102 | if (ptr_val.tag() == .decl_ref_mut) { |
| 10990 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); | 11103 | try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty); |
| 10991 | return; | 11104 | return; |
| ... | @@ -11013,21 +11126,21 @@ fn storePtrVal( | ... | @@ -11013,21 +11126,21 @@ fn storePtrVal( |
| 11013 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { | 11126 | if (decl_ref_mut.data.runtime_index < block.runtime_index) { |
| 11014 | if (block.runtime_cond) |cond_src| { | 11127 | if (block.runtime_cond) |cond_src| { |
| 11015 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 11132 | break :msg msg; |
| 11020 | }; | 11133 | }; |
| 11021 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 11134 | return sema.failWithOwnedErrorMsg(msg); |
| 11022 | } | 11135 | } |
| 11023 | if (block.runtime_loop) |loop_src| { | 11136 | if (block.runtime_loop) |loop_src| { |
| 11024 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 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 | break :msg msg; | 11141 | break :msg msg; |
| 11029 | }; | 11142 | }; |
| 11030 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 11143 | return sema.failWithOwnedErrorMsg(msg); |
| 11031 | } | 11144 | } |
| 11032 | unreachable; | 11145 | unreachable; |
| 11033 | } | 11146 | } |
| ... | @@ -11191,7 +11304,7 @@ fn analyzeLoad( | ... | @@ -11191,7 +11304,7 @@ fn analyzeLoad( |
| 11191 | const ptr_ty = sema.typeOf(ptr); | 11304 | const ptr_ty = sema.typeOf(ptr); |
| 11192 | const elem_ty = switch (ptr_ty.zigTypeTag()) { | 11305 | const elem_ty = switch (ptr_ty.zigTypeTag()) { |
| 11193 | .Pointer => ptr_ty.elemType(), | 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 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { | 11309 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 11197 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { | 11310 | if (try ptr_val.pointerDeref(sema.arena)) |elem_val| { |
| ... | @@ -11213,7 +11326,7 @@ fn analyzeSliceLen( | ... | @@ -11213,7 +11326,7 @@ fn analyzeSliceLen( |
| 11213 | if (slice_val.isUndef()) { | 11326 | if (slice_val.isUndef()) { |
| 11214 | return sema.addConstUndef(Type.initTag(.usize)); | 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 | try sema.requireRuntimeBlock(block, src); | 11331 | try sema.requireRuntimeBlock(block, src); |
| 11219 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); | 11332 | return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst); |
| ... | @@ -11283,7 +11396,7 @@ fn analyzeSlice( | ... | @@ -11283,7 +11396,7 @@ fn analyzeSlice( |
| 11283 | const array_ptr_ty = sema.typeOf(array_ptr); | 11396 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 11284 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { | 11397 | const ptr_child = switch (array_ptr_ty.zigTypeTag()) { |
| 11285 | .Pointer => array_ptr_ty.elemType(), | 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 | var array_type = ptr_child; | 11402 | var array_type = ptr_child; |
| ... | @@ -11296,11 +11409,11 @@ fn analyzeSlice( | ... | @@ -11296,11 +11409,11 @@ fn analyzeSlice( |
| 11296 | break :blk ptr_child.elemType().elemType(); | 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 | break :blk ptr_child.elemType(); | 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 | const slice_sentinel = if (sentinel_opt != .none) blk: { | 11419 | const slice_sentinel = if (sentinel_opt != .none) blk: { |
| ... | @@ -11316,7 +11429,7 @@ fn analyzeSlice( | ... | @@ -11316,7 +11429,7 @@ fn analyzeSlice( |
| 11316 | const start_u64 = start_val.toUnsignedInt(); | 11429 | const start_u64 = start_val.toUnsignedInt(); |
| 11317 | const end_u64 = end_val.toUnsignedInt(); | 11430 | const end_u64 = end_val.toUnsignedInt(); |
| 11318 | if (start_u64 > end_u64) { | 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 | const len = end_u64 - start_u64; | 11435 | const len = end_u64 - start_u64; |
| ... | @@ -11341,7 +11454,7 @@ fn analyzeSlice( | ... | @@ -11341,7 +11454,7 @@ fn analyzeSlice( |
| 11341 | }); | 11454 | }); |
| 11342 | _ = return_type; | 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 | /// Asserts that lhs and rhs types are both numeric. | 11460 | /// Asserts that lhs and rhs types are both numeric. |
| ... | @@ -11366,13 +11479,13 @@ fn cmpNumeric( | ... | @@ -11366,13 +11479,13 @@ fn cmpNumeric( |
| 11366 | | 11479 | |
| 11367 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { | 11480 | if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) { |
| 11368 | if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) { | 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 | lhs_ty.arrayLen(), rhs_ty.arrayLen(), | 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 | } else if (lhs_ty_tag == .Vector or rhs_ty_tag == .Vector) { | 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 | lhs_ty, rhs_ty, | 11489 | lhs_ty, rhs_ty, |
| 11377 | }); | 11490 | }); |
| 11378 | } | 11491 | } |
| ... | @@ -11522,7 +11635,7 @@ fn cmpNumeric( | ... | @@ -11522,7 +11635,7 @@ fn cmpNumeric( |
| 11522 | const dest_type = if (dest_float_type) |ft| ft else blk: { | 11635 | const dest_type = if (dest_float_type) |ft| ft else blk: { |
| 11523 | const max_bits = std.math.max(lhs_bits, rhs_bits); | 11636 | const max_bits = std.math.max(lhs_bits, rhs_bits); |
| 11524 | const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { | 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 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; | 11640 | const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; |
| 11528 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); | 11641 | break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); |
| ... | @@ -11569,8 +11682,8 @@ fn wrapErrorUnion( | ... | @@ -11569,8 +11682,8 @@ fn wrapErrorUnion( |
| 11569 | const expected_name = val.castTag(.@"error").?.data.name; | 11682 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11570 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; | 11683 | const n = dest_err_set_ty.castTag(.error_set_single).?.data; |
| 11571 | if (!mem.eql(u8, expected_name, n)) { | 11684 | if (!mem.eql(u8, expected_name, n)) { |
| 11572 | return sema.mod.fail( | 11685 | return sema.fail( |
| 11573 | &block.base, | 11686 | block, |
| 11574 | inst_src, | 11687 | inst_src, |
| 11575 | "expected type '{}', found type '{}'", | 11688 | "expected type '{}', found type '{}'", |
| 11576 | .{ dest_err_set_ty, inst_ty }, | 11689 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11587,8 +11700,8 @@ fn wrapErrorUnion( | ... | @@ -11587,8 +11700,8 @@ fn wrapErrorUnion( |
| 11587 | if (mem.eql(u8, expected_name, name)) break true; | 11700 | if (mem.eql(u8, expected_name, name)) break true; |
| 11588 | } else false; | 11701 | } else false; |
| 11589 | if (!found) { | 11702 | if (!found) { |
| 11590 | return sema.mod.fail( | 11703 | return sema.fail( |
| 11591 | &block.base, | 11704 | block, |
| 11592 | inst_src, | 11705 | inst_src, |
| 11593 | "expected type '{}', found type '{}'", | 11706 | "expected type '{}', found type '{}'", |
| 11594 | .{ dest_err_set_ty, inst_ty }, | 11707 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11599,8 +11712,8 @@ fn wrapErrorUnion( | ... | @@ -11599,8 +11712,8 @@ fn wrapErrorUnion( |
| 11599 | const expected_name = val.castTag(.@"error").?.data.name; | 11712 | const expected_name = val.castTag(.@"error").?.data.name; |
| 11600 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; | 11713 | const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map; |
| 11601 | if (!map.contains(expected_name)) { | 11714 | if (!map.contains(expected_name)) { |
| 11602 | return sema.mod.fail( | 11715 | return sema.fail( |
| 11603 | &block.base, | 11716 | block, |
| 11604 | inst_src, | 11717 | inst_src, |
| 11605 | "expected type '{}', found type '{}'", | 11718 | "expected type '{}', found type '{}'", |
| 11606 | .{ dest_err_set_ty, inst_ty }, | 11719 | .{ dest_err_set_ty, inst_ty }, |
| ... | @@ -11735,18 +11848,18 @@ fn resolvePeerTypes( | ... | @@ -11735,18 +11848,18 @@ fn resolvePeerTypes( |
| 11735 | ); | 11848 | ); |
| 11736 | | 11849 | |
| 11737 | const msg = msg: { | 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 | errdefer msg.destroy(sema.gpa); | 11852 | errdefer msg.destroy(sema.gpa); |
| 11740 | | 11853 | |
| 11741 | if (chosen_src) |src_loc| | 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 | if (candidate_src) |src_loc| | 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 | break :msg msg; | 11860 | break :msg msg; |
| 11748 | }; | 11861 | }; |
| 11749 | return sema.mod.failWithOwnedErrorMsg(&block.base, msg); | 11862 | return sema.failWithOwnedErrorMsg(msg); |
| 11750 | } | 11863 | } |
| 11751 | | 11864 | |
| 11752 | return sema.typeOf(chosen); | 11865 | return sema.typeOf(chosen); |
| ... | @@ -11765,7 +11878,7 @@ pub fn resolveTypeLayout( | ... | @@ -11765,7 +11878,7 @@ pub fn resolveTypeLayout( |
| 11765 | switch (struct_obj.status) { | 11878 | switch (struct_obj.status) { |
| 11766 | .none, .have_field_types => {}, | 11879 | .none, .have_field_types => {}, |
| 11767 | .field_types_wip, .layout_wip => { | 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 | .have_layout => return, | 11883 | .have_layout => return, |
| 11771 | } | 11884 | } |
| ... | @@ -11786,7 +11899,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type | ... | @@ -11786,7 +11899,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11786 | switch (struct_obj.status) { | 11899 | switch (struct_obj.status) { |
| 11787 | .none => {}, | 11900 | .none => {}, |
| 11788 | .field_types_wip => { | 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 | .have_field_types, .have_layout, .layout_wip => return ty, | 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,7 +11926,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type |
| 11813 | switch (union_obj.status) { | 11926 | switch (union_obj.status) { |
| 11814 | .none => {}, | 11927 | .none => {}, |
| 11815 | .field_types_wip => { | 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 | .have_field_types, .have_layout, .layout_wip => return ty, | 11931 | .have_field_types, .have_layout, .layout_wip => return ty, |
| 11819 | } | 11932 | } |
| ... | @@ -12232,7 +12345,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -12232,7 +12345,7 @@ fn generateUnionTagTypeNumbered( |
| 12232 | .val = enum_val, | 12345 | .val = enum_val, |
| 12233 | }); | 12346 | }); |
| 12234 | new_decl.owns_tv = true; | 12347 | new_decl.owns_tv = true; |
| 12235 | errdefer sema.mod.abortAnonDecl(new_decl); | 12348 | errdefer mod.abortAnonDecl(new_decl); |
| 12236 | | 12349 | |
| 12237 | enum_obj.* = .{ | 12350 | enum_obj.* = .{ |
| 12238 | .owner_decl = new_decl, | 12351 | .owner_decl = new_decl, |
| ... | @@ -12268,7 +12381,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) | ... | @@ -12268,7 +12381,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32) |
| 12268 | .val = enum_val, | 12381 | .val = enum_val, |
| 12269 | }); | 12382 | }); |
| 12270 | new_decl.owns_tv = true; | 12383 | new_decl.owns_tv = true; |
| 12271 | errdefer sema.mod.abortAnonDecl(new_decl); | 12384 | errdefer mod.abortAnonDecl(new_decl); |
| 12272 | | 12385 | |
| 12273 | enum_obj.* = .{ | 12386 | enum_obj.* = .{ |
| 12274 | .owner_decl = new_decl, | 12387 | .owner_decl = new_decl, |
| ... | @@ -12752,8 +12865,8 @@ pub fn analyzeAddrspace( | ... | @@ -12752,8 +12865,8 @@ pub fn analyzeAddrspace( |
| 12752 | .pointer => "pointers", | 12865 | .pointer => "pointers", |
| 12753 | }; | 12866 | }; |
| 12754 | | 12867 | |
| 12755 | return sema.mod.fail( | 12868 | return sema.fail( |
| 12756 | &block.base, | 12869 | block, |
| 12757 | src, | 12870 | src, |
| 12758 | "{s} with address space '{s}' are not supported on {s}", | 12871 | "{s} with address space '{s}' are not supported on {s}", |
| 12759 | .{ entity, @tagName(address_space), arch.genericName() }, | 12872 | .{ entity, @tagName(address_space), arch.genericName() }, |