| ... | @@ -309,17 +309,17 @@ pub const Block = struct { | ... | @@ -309,17 +309,17 @@ pub const Block = struct { |
| 309 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; | 309 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 310 | break :blk src_loc; | 310 | break :blk src_loc; |
| 311 | } else blk: { | 311 | } else blk: { |
| 312 | const src_decl = sema.mod.declPtr(rt.block.src_decl); | 312 | const src_decl = mod.declPtr(rt.block.src_decl); |
| 313 | break :blk rt.func_src.toSrcLoc(src_decl, mod); | 313 | break :blk rt.func_src.toSrcLoc(src_decl, mod); |
| 314 | }; | 314 | }; |
| 315 | if (rt.return_ty.isGenericPoison()) { | 315 | if (rt.return_ty.isGenericPoison()) { |
| 316 | return sema.mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); | 316 | return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); |
| 317 | } | 317 | } |
| 318 | try sema.mod.errNoteNonLazy( | 318 | try mod.errNoteNonLazy( |
| 319 | src_loc, | 319 | src_loc, |
| 320 | parent, | 320 | parent, |
| 321 | prefix ++ "the function returns a comptime-only type '{}'", | 321 | prefix ++ "the function returns a comptime-only type '{}'", |
| 322 | .{rt.return_ty.fmt(sema.mod)}, | 322 | .{rt.return_ty.fmt(mod)}, |
| 323 | ); | 323 | ); |
| 324 | try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty); | 324 | try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty); |
| 325 | }, | 325 | }, |
| ... | @@ -2825,7 +2825,6 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2825,7 +2825,6 @@ fn createAnonymousDeclTypeNamed( |
| 2825 | ) !Decl.Index { | 2825 | ) !Decl.Index { |
| 2826 | const mod = sema.mod; | 2826 | const mod = sema.mod; |
| 2827 | const gpa = sema.gpa; | 2827 | const gpa = sema.gpa; |
| 2828 | const ip = &mod.intern_pool; | | |
| 2829 | const namespace = block.namespace; | 2828 | const namespace = block.namespace; |
| 2830 | const src_scope = block.wip_capture_scope; | 2829 | const src_scope = block.wip_capture_scope; |
| 2831 | const src_decl = mod.declPtr(block.src_decl); | 2830 | const src_decl = mod.declPtr(block.src_decl); |
| ... | @@ -2842,12 +2841,8 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2842,12 +2841,8 @@ fn createAnonymousDeclTypeNamed( |
| 2842 | // This name is also used as the key in the parent namespace so it cannot be | 2841 | // This name is also used as the key in the parent namespace so it cannot be |
| 2843 | // renamed. | 2842 | // renamed. |
| 2844 | | 2843 | |
| 2845 | // This ensureUnusedCapacity protects against the src_decl slice from being | 2844 | const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ |
| 2846 | // reallocated during the call to `getOrPutStringFmt`. | 2845 | src_decl.name.fmt(&mod.intern_pool), anon_prefix, @enumToInt(new_decl_index), |
| 2847 | try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(src_decl.name).len + | | |
| 2848 | anon_prefix.len + 20); | | |
| 2849 | const name = ip.getOrPutStringFmt(gpa, "{s}__{s}_{d}", .{ | | |
| 2850 | ip.stringToSlice(src_decl.name), anon_prefix, @enumToInt(new_decl_index), | | |
| 2851 | }) catch unreachable; | 2846 | }) catch unreachable; |
| 2852 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2847 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2853 | return new_decl_index; | 2848 | return new_decl_index; |
| ... | @@ -2863,8 +2858,9 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2863,8 +2858,9 @@ fn createAnonymousDeclTypeNamed( |
| 2863 | | 2858 | |
| 2864 | var buf = std.ArrayList(u8).init(gpa); | 2859 | var buf = std.ArrayList(u8).init(gpa); |
| 2865 | defer buf.deinit(); | 2860 | defer buf.deinit(); |
| 2866 | try buf.appendSlice(ip.stringToSlice(mod.declPtr(block.src_decl).name)); | 2861 | |
| 2867 | try buf.appendSlice("("); | 2862 | const writer = buf.writer(); |
| | 2863 | try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)}); |
| 2868 | | 2864 | |
| 2869 | var arg_i: usize = 0; | 2865 | var arg_i: usize = 0; |
| 2870 | for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) { | 2866 | for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) { |
| ... | @@ -2878,8 +2874,8 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2878,8 +2874,8 @@ fn createAnonymousDeclTypeNamed( |
| 2878 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch | 2874 | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch |
| 2879 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); | 2875 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); |
| 2880 | | 2876 | |
| 2881 | if (arg_i != 0) try buf.appendSlice(","); | 2877 | if (arg_i != 0) try writer.writeByte(','); |
| 2882 | try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)}); | 2878 | try writer.print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)}); |
| 2883 | | 2879 | |
| 2884 | arg_i += 1; | 2880 | arg_i += 1; |
| 2885 | continue; | 2881 | continue; |
| ... | @@ -2887,8 +2883,8 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2887,8 +2883,8 @@ fn createAnonymousDeclTypeNamed( |
| 2887 | else => continue, | 2883 | else => continue, |
| 2888 | }; | 2884 | }; |
| 2889 | | 2885 | |
| 2890 | try buf.appendSlice(")"); | 2886 | try writer.writeByte(')'); |
| 2891 | const name = try ip.getOrPutString(gpa, buf.items); | 2887 | const name = try mod.intern_pool.getOrPutString(gpa, buf.items); |
| 2892 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2888 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2893 | return new_decl_index; | 2889 | return new_decl_index; |
| 2894 | }, | 2890 | }, |
| ... | @@ -2901,17 +2897,9 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2901,17 +2897,9 @@ fn createAnonymousDeclTypeNamed( |
| 2901 | .dbg_var_ptr, .dbg_var_val => { | 2897 | .dbg_var_ptr, .dbg_var_val => { |
| 2902 | if (zir_data[i].str_op.operand != ref) continue; | 2898 | if (zir_data[i].str_op.operand != ref) continue; |
| 2903 | | 2899 | |
| 2904 | // This ensureUnusedCapacity protects against the src_decl | 2900 | const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{ |
| 2905 | // slice from being reallocated during the call to | 2901 | src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code), |
| 2906 | // `getOrPutStringFmt`. | 2902 | }); |
| 2907 | const zir_str = zir_data[i].str_op.getStr(sema.code); | | |
| 2908 | try ip.string_bytes.ensureUnusedCapacity( | | |
| 2909 | gpa, | | |
| 2910 | ip.stringToSlice(src_decl.name).len + zir_str.len + 10, | | |
| 2911 | ); | | |
| 2912 | const name = ip.getOrPutStringFmt(gpa, "{s}.{s}", .{ | | |
| 2913 | ip.stringToSlice(src_decl.name), zir_str, | | |
| 2914 | }) catch unreachable; | | |
| 2915 | | 2903 | |
| 2916 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2904 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2917 | return new_decl_index; | 2905 | return new_decl_index; |
| ... | @@ -4538,8 +4526,8 @@ fn validateStructInit( | ... | @@ -4538,8 +4526,8 @@ fn validateStructInit( |
| 4538 | continue; | 4526 | continue; |
| 4539 | } | 4527 | } |
| 4540 | const field_name = struct_ty.structFieldName(i, mod); | 4528 | const field_name = struct_ty.structFieldName(i, mod); |
| 4541 | const template = "missing struct field: {s}"; | 4529 | const template = "missing struct field: {}"; |
| 4542 | const args = .{ip.stringToSlice(field_name)}; | 4530 | const args = .{field_name.fmt(ip)}; |
| 4543 | if (root_msg) |msg| { | 4531 | if (root_msg) |msg| { |
| 4544 | try sema.errNote(block, init_src, msg, template, args); | 4532 | try sema.errNote(block, init_src, msg, template, args); |
| 4545 | } else { | 4533 | } else { |
| ... | @@ -4560,12 +4548,12 @@ fn validateStructInit( | ... | @@ -4560,12 +4548,12 @@ fn validateStructInit( |
| 4560 | | 4548 | |
| 4561 | if (root_msg) |msg| { | 4549 | if (root_msg) |msg| { |
| 4562 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 4550 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4563 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); | 4551 | const fqn = try struct_obj.getFullyQualifiedName(mod); |
| 4564 | try mod.errNoteNonLazy( | 4552 | try mod.errNoteNonLazy( |
| 4565 | struct_obj.srcLoc(mod), | 4553 | struct_obj.srcLoc(mod), |
| 4566 | msg, | 4554 | msg, |
| 4567 | "struct '{s}' declared here", | 4555 | "struct '{}' declared here", |
| 4568 | .{fqn}, | 4556 | .{fqn.fmt(ip)}, |
| 4569 | ); | 4557 | ); |
| 4570 | } | 4558 | } |
| 4571 | root_msg = null; | 4559 | root_msg = null; |
| ... | @@ -4682,8 +4670,8 @@ fn validateStructInit( | ... | @@ -4682,8 +4670,8 @@ fn validateStructInit( |
| 4682 | continue; | 4670 | continue; |
| 4683 | } | 4671 | } |
| 4684 | const field_name = struct_ty.structFieldName(i, mod); | 4672 | const field_name = struct_ty.structFieldName(i, mod); |
| 4685 | const template = "missing struct field: {s}"; | 4673 | const template = "missing struct field: {}"; |
| 4686 | const args = .{ip.stringToSlice(field_name)}; | 4674 | const args = .{field_name.fmt(ip)}; |
| 4687 | if (root_msg) |msg| { | 4675 | if (root_msg) |msg| { |
| 4688 | try sema.errNote(block, init_src, msg, template, args); | 4676 | try sema.errNote(block, init_src, msg, template, args); |
| 4689 | } else { | 4677 | } else { |
| ... | @@ -4696,12 +4684,12 @@ fn validateStructInit( | ... | @@ -4696,12 +4684,12 @@ fn validateStructInit( |
| 4696 | | 4684 | |
| 4697 | if (root_msg) |msg| { | 4685 | if (root_msg) |msg| { |
| 4698 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 4686 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 4699 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); | 4687 | const fqn = try struct_obj.getFullyQualifiedName(mod); |
| 4700 | try sema.mod.errNoteNonLazy( | 4688 | try mod.errNoteNonLazy( |
| 4701 | struct_obj.srcLoc(mod), | 4689 | struct_obj.srcLoc(mod), |
| 4702 | msg, | 4690 | msg, |
| 4703 | "struct '{s}' declared here", | 4691 | "struct '{}' declared here", |
| 4704 | .{fqn}, | 4692 | .{fqn.fmt(ip)}, |
| 4705 | ); | 4693 | ); |
| 4706 | } | 4694 | } |
| 4707 | root_msg = null; | 4695 | root_msg = null; |
| ... | @@ -4942,11 +4930,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4942,11 +4930,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4942 | const operand_ty = sema.typeOf(operand); | 4930 | const operand_ty = sema.typeOf(operand); |
| 4943 | | 4931 | |
| 4944 | if (operand_ty.zigTypeTag(mod) != .Pointer) { | 4932 | if (operand_ty.zigTypeTag(mod) != .Pointer) { |
| 4945 | return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(sema.mod)}); | 4933 | return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(mod)}); |
| 4946 | } else switch (operand_ty.ptrSize(mod)) { | 4934 | } else switch (operand_ty.ptrSize(mod)) { |
| 4947 | .One, .C => {}, | 4935 | .One, .C => {}, |
| 4948 | .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(sema.mod)}), | 4936 | .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(mod)}), |
| 4949 | .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}), | 4937 | .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(mod)}), |
| 4950 | } | 4938 | } |
| 4951 | | 4939 | |
| 4952 | if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) { | 4940 | if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) { |
| ... | @@ -4965,11 +4953,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4965,11 +4953,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4965 | block, | 4953 | block, |
| 4966 | src, | 4954 | src, |
| 4967 | "values of type '{}' must be comptime-known, but operand value is runtime-known", | 4955 | "values of type '{}' must be comptime-known, but operand value is runtime-known", |
| 4968 | .{elem_ty.fmt(sema.mod)}, | 4956 | .{elem_ty.fmt(mod)}, |
| 4969 | ); | 4957 | ); |
| 4970 | errdefer msg.destroy(sema.gpa); | 4958 | errdefer msg.destroy(sema.gpa); |
| 4971 | | 4959 | |
| 4972 | const src_decl = sema.mod.declPtr(block.src_decl); | 4960 | const src_decl = mod.declPtr(block.src_decl); |
| 4973 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty); | 4961 | try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty); |
| 4974 | break :msg msg; | 4962 | break :msg msg; |
| 4975 | }; | 4963 | }; |
| ... | @@ -4982,7 +4970,7 @@ fn failWithBadMemberAccess( | ... | @@ -4982,7 +4970,7 @@ fn failWithBadMemberAccess( |
| 4982 | block: *Block, | 4970 | block: *Block, |
| 4983 | agg_ty: Type, | 4971 | agg_ty: Type, |
| 4984 | field_src: LazySrcLoc, | 4972 | field_src: LazySrcLoc, |
| 4985 | field_name_nts: InternPool.NullTerminatedString, | 4973 | field_name: InternPool.NullTerminatedString, |
| 4986 | ) CompileError { | 4974 | ) CompileError { |
| 4987 | const mod = sema.mod; | 4975 | const mod = sema.mod; |
| 4988 | const kw_name = switch (agg_ty.zigTypeTag(mod)) { | 4976 | const kw_name = switch (agg_ty.zigTypeTag(mod)) { |
| ... | @@ -4992,15 +4980,14 @@ fn failWithBadMemberAccess( | ... | @@ -4992,15 +4980,14 @@ fn failWithBadMemberAccess( |
| 4992 | .Enum => "enum", | 4980 | .Enum => "enum", |
| 4993 | else => unreachable, | 4981 | else => unreachable, |
| 4994 | }; | 4982 | }; |
| 4995 | const field_name = mod.intern_pool.stringToSlice(field_name_nts); | 4983 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (mod.declIsRoot(some)) { |
| 4996 | if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) { | 4984 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{}'", .{ |
| 4997 | return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{ | 4985 | agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool), |
| 4998 | agg_ty.fmt(sema.mod), field_name, | | |
| 4999 | }); | 4986 | }); |
| 5000 | }; | 4987 | }; |
| 5001 | const msg = msg: { | 4988 | const msg = msg: { |
| 5002 | const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{ | 4989 | const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{}'", .{ |
| 5003 | kw_name, agg_ty.fmt(sema.mod), field_name, | 4990 | kw_name, agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool), |
| 5004 | }); | 4991 | }); |
| 5005 | errdefer msg.destroy(sema.gpa); | 4992 | errdefer msg.destroy(sema.gpa); |
| 5006 | try sema.addDeclaredHereNote(msg, agg_ty); | 4993 | try sema.addDeclaredHereNote(msg, agg_ty); |
| ... | @@ -5018,16 +5005,15 @@ fn failWithBadStructFieldAccess( | ... | @@ -5018,16 +5005,15 @@ fn failWithBadStructFieldAccess( |
| 5018 | ) CompileError { | 5005 | ) CompileError { |
| 5019 | const mod = sema.mod; | 5006 | const mod = sema.mod; |
| 5020 | const gpa = sema.gpa; | 5007 | const gpa = sema.gpa; |
| 5021 | const ip = &mod.intern_pool; | | |
| 5022 | | 5008 | |
| 5023 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); | 5009 | const fqn = try struct_obj.getFullyQualifiedName(mod); |
| 5024 | | 5010 | |
| 5025 | const msg = msg: { | 5011 | const msg = msg: { |
| 5026 | const msg = try sema.errMsg( | 5012 | const msg = try sema.errMsg( |
| 5027 | block, | 5013 | block, |
| 5028 | field_src, | 5014 | field_src, |
| 5029 | "no field named '{s}' in struct '{s}'", | 5015 | "no field named '{}' in struct '{}'", |
| 5030 | .{ ip.stringToSlice(field_name), fqn }, | 5016 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, |
| 5031 | ); | 5017 | ); |
| 5032 | errdefer msg.destroy(gpa); | 5018 | errdefer msg.destroy(gpa); |
| 5033 | try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{}); | 5019 | try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{}); |
| ... | @@ -5045,16 +5031,15 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5045,16 +5031,15 @@ fn failWithBadUnionFieldAccess( |
| 5045 | ) CompileError { | 5031 | ) CompileError { |
| 5046 | const mod = sema.mod; | 5032 | const mod = sema.mod; |
| 5047 | const gpa = sema.gpa; | 5033 | const gpa = sema.gpa; |
| 5048 | const ip = &mod.intern_pool; | | |
| 5049 | | 5034 | |
| 5050 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); | 5035 | const fqn = try union_obj.getFullyQualifiedName(mod); |
| 5051 | | 5036 | |
| 5052 | const msg = msg: { | 5037 | const msg = msg: { |
| 5053 | const msg = try sema.errMsg( | 5038 | const msg = try sema.errMsg( |
| 5054 | block, | 5039 | block, |
| 5055 | field_src, | 5040 | field_src, |
| 5056 | "no field named '{s}' in union '{s}'", | 5041 | "no field named '{}' in union '{}'", |
| 5057 | .{ ip.stringToSlice(field_name), fqn }, | 5042 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, |
| 5058 | ); | 5043 | ); |
| 5059 | errdefer msg.destroy(gpa); | 5044 | errdefer msg.destroy(gpa); |
| 5060 | try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{}); | 5045 | try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{}); |
| ... | @@ -5334,7 +5319,9 @@ fn zirCompileLog( | ... | @@ -5334,7 +5319,9 @@ fn zirCompileLog( |
| 5334 | sema: *Sema, | 5319 | sema: *Sema, |
| 5335 | extended: Zir.Inst.Extended.InstData, | 5320 | extended: Zir.Inst.Extended.InstData, |
| 5336 | ) CompileError!Air.Inst.Ref { | 5321 | ) CompileError!Air.Inst.Ref { |
| 5337 | var managed = sema.mod.compile_log_text.toManaged(sema.gpa); | 5322 | const mod = sema.mod; |
| | 5323 | |
| | 5324 | var managed = mod.compile_log_text.toManaged(sema.gpa); |
| 5338 | defer sema.mod.compile_log_text = managed.moveToUnmanaged(); | 5325 | defer sema.mod.compile_log_text = managed.moveToUnmanaged(); |
| 5339 | const writer = managed.writer(); | 5326 | const writer = managed.writer(); |
| 5340 | | 5327 | |
| ... | @@ -5349,16 +5336,16 @@ fn zirCompileLog( | ... | @@ -5349,16 +5336,16 @@ fn zirCompileLog( |
| 5349 | const arg_ty = sema.typeOf(arg); | 5336 | const arg_ty = sema.typeOf(arg); |
| 5350 | if (try sema.resolveMaybeUndefLazyVal(arg)) |val| { | 5337 | if (try sema.resolveMaybeUndefLazyVal(arg)) |val| { |
| 5351 | try writer.print("@as({}, {})", .{ | 5338 | try writer.print("@as({}, {})", .{ |
| 5352 | arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod), | 5339 | arg_ty.fmt(mod), val.fmtValue(arg_ty, mod), |
| 5353 | }); | 5340 | }); |
| 5354 | } else { | 5341 | } else { |
| 5355 | try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(sema.mod)}); | 5342 | try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(mod)}); |
| 5356 | } | 5343 | } |
| 5357 | } | 5344 | } |
| 5358 | try writer.print("\n", .{}); | 5345 | try writer.print("\n", .{}); |
| 5359 | | 5346 | |
| 5360 | const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index; | 5347 | const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index; |
| 5361 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, decl_index); | 5348 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); |
| 5362 | if (!gop.found_existing) { | 5349 | if (!gop.found_existing) { |
| 5363 | gop.value_ptr.* = src_node; | 5350 | gop.value_ptr.* = src_node; |
| 5364 | } | 5351 | } |
| ... | @@ -5509,7 +5496,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5509,7 +5496,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5509 | if (!mod.comp.bin_file.options.link_libc) | 5496 | if (!mod.comp.bin_file.options.link_libc) |
| 5510 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); | 5497 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 5511 | | 5498 | |
| 5512 | const gop = try sema.mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index); | 5499 | const gop = try mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index); |
| 5513 | if (!gop.found_existing) { | 5500 | if (!gop.found_existing) { |
| 5514 | var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len); | 5501 | var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len); |
| 5515 | errdefer { | 5502 | errdefer { |
| ... | @@ -5869,13 +5856,13 @@ pub fn analyzeExport( | ... | @@ -5869,13 +5856,13 @@ pub fn analyzeExport( |
| 5869 | sema: *Sema, | 5856 | sema: *Sema, |
| 5870 | block: *Block, | 5857 | block: *Block, |
| 5871 | src: LazySrcLoc, | 5858 | src: LazySrcLoc, |
| 5872 | borrowed_options: std.builtin.ExportOptions, | 5859 | options: Module.Export.Options, |
| 5873 | exported_decl_index: Decl.Index, | 5860 | exported_decl_index: Decl.Index, |
| 5874 | ) !void { | 5861 | ) !void { |
| 5875 | const Export = Module.Export; | 5862 | const Export = Module.Export; |
| 5876 | const mod = sema.mod; | 5863 | const mod = sema.mod; |
| 5877 | | 5864 | |
| 5878 | if (borrowed_options.linkage == .Internal) { | 5865 | if (options.linkage == .Internal) { |
| 5879 | return; | 5866 | return; |
| 5880 | } | 5867 | } |
| 5881 | | 5868 | |
| ... | @@ -5884,10 +5871,10 @@ pub fn analyzeExport( | ... | @@ -5884,10 +5871,10 @@ pub fn analyzeExport( |
| 5884 | | 5871 | |
| 5885 | if (!try sema.validateExternType(exported_decl.ty, .other)) { | 5872 | if (!try sema.validateExternType(exported_decl.ty, .other)) { |
| 5886 | const msg = msg: { | 5873 | const msg = msg: { |
| 5887 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)}); | 5874 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(mod)}); |
| 5888 | errdefer msg.destroy(sema.gpa); | 5875 | errdefer msg.destroy(sema.gpa); |
| 5889 | | 5876 | |
| 5890 | const src_decl = sema.mod.declPtr(block.src_decl); | 5877 | const src_decl = mod.declPtr(block.src_decl); |
| 5891 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other); | 5878 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other); |
| 5892 | | 5879 | |
| 5893 | try sema.addDeclaredHereNote(msg, exported_decl.ty); | 5880 | try sema.addDeclaredHereNote(msg, exported_decl.ty); |
| ... | @@ -5913,14 +5900,8 @@ pub fn analyzeExport( | ... | @@ -5913,14 +5900,8 @@ pub fn analyzeExport( |
| 5913 | const new_export = try gpa.create(Export); | 5900 | const new_export = try gpa.create(Export); |
| 5914 | errdefer gpa.destroy(new_export); | 5901 | errdefer gpa.destroy(new_export); |
| 5915 | | 5902 | |
| 5916 | const symbol_name = try mod.intern_pool.getOrPutString(gpa, borrowed_options.name); | | |
| 5917 | const section = try mod.intern_pool.getOrPutStringOpt(gpa, borrowed_options.section); | | |
| 5918 | | | |
| 5919 | new_export.* = .{ | 5903 | new_export.* = .{ |
| 5920 | .name = symbol_name, | 5904 | .opts = options, |
| 5921 | .linkage = borrowed_options.linkage, | | |
| 5922 | .section = section, | | |
| 5923 | .visibility = borrowed_options.visibility, | | |
| 5924 | .src = src, | 5905 | .src = src, |
| 5925 | .owner_decl = sema.owner_decl_index, | 5906 | .owner_decl = sema.owner_decl_index, |
| 5926 | .src_decl = block.src_decl, | 5907 | .src_decl = block.src_decl, |
| ... | @@ -6198,7 +6179,7 @@ fn lookupInNamespace( | ... | @@ -6198,7 +6179,7 @@ fn lookupInNamespace( |
| 6198 | | 6179 | |
| 6199 | const namespace = mod.namespacePtr(namespace_index); | 6180 | const namespace = mod.namespacePtr(namespace_index); |
| 6200 | const namespace_decl_index = namespace.getDeclIndex(mod); | 6181 | const namespace_decl_index = namespace.getDeclIndex(mod); |
| 6201 | const namespace_decl = sema.mod.declPtr(namespace_decl_index); | 6182 | const namespace_decl = mod.declPtr(namespace_decl_index); |
| 6202 | if (namespace_decl.analysis == .file_failure) { | 6183 | if (namespace_decl.analysis == .file_failure) { |
| 6203 | try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index); | 6184 | try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index); |
| 6204 | return error.AnalysisFail; | 6185 | return error.AnalysisFail; |
| ... | @@ -6531,7 +6512,7 @@ fn zirCall( | ... | @@ -6531,7 +6512,7 @@ fn zirCall( |
| 6531 | // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction. | 6512 | // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction. |
| 6532 | const call_dbg_node = inst - 1; | 6513 | const call_dbg_node = inst - 1; |
| 6533 | | 6514 | |
| 6534 | if (sema.mod.backendSupportsFeature(.error_return_trace) and sema.mod.comp.bin_file.options.error_return_tracing and | 6515 | if (mod.backendSupportsFeature(.error_return_trace) and mod.comp.bin_file.options.error_return_tracing and |
| 6535 | !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace)) | 6516 | !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace)) |
| 6536 | { | 6517 | { |
| 6537 | const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: { | 6518 | const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: { |
| ... | @@ -6599,7 +6580,7 @@ fn checkCallArgumentCount( | ... | @@ -6599,7 +6580,7 @@ fn checkCallArgumentCount( |
| 6599 | { | 6580 | { |
| 6600 | const msg = msg: { | 6581 | const msg = msg: { |
| 6601 | const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{ | 6582 | const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{ |
| 6602 | callee_ty.fmt(sema.mod), | 6583 | callee_ty.fmt(mod), |
| 6603 | }); | 6584 | }); |
| 6604 | errdefer msg.destroy(sema.gpa); | 6585 | errdefer msg.destroy(sema.gpa); |
| 6605 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); | 6586 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); |
| ... | @@ -6610,7 +6591,7 @@ fn checkCallArgumentCount( | ... | @@ -6610,7 +6591,7 @@ fn checkCallArgumentCount( |
| 6610 | }, | 6591 | }, |
| 6611 | else => {}, | 6592 | else => {}, |
| 6612 | } | 6593 | } |
| 6613 | return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(sema.mod)}); | 6594 | return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(mod)}); |
| 6614 | }; | 6595 | }; |
| 6615 | | 6596 | |
| 6616 | const func_ty_info = mod.typeToFunc(func_ty).?; | 6597 | const func_ty_info = mod.typeToFunc(func_ty).?; |
| ... | @@ -6640,7 +6621,7 @@ fn checkCallArgumentCount( | ... | @@ -6640,7 +6621,7 @@ fn checkCallArgumentCount( |
| 6640 | ); | 6621 | ); |
| 6641 | errdefer msg.destroy(sema.gpa); | 6622 | errdefer msg.destroy(sema.gpa); |
| 6642 | | 6623 | |
| 6643 | if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 6624 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); |
| 6644 | break :msg msg; | 6625 | break :msg msg; |
| 6645 | }; | 6626 | }; |
| 6646 | return sema.failWithOwnedErrorMsg(msg); | 6627 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -6666,7 +6647,7 @@ fn callBuiltin( | ... | @@ -6666,7 +6647,7 @@ fn callBuiltin( |
| 6666 | }, | 6647 | }, |
| 6667 | else => {}, | 6648 | else => {}, |
| 6668 | } | 6649 | } |
| 6669 | std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(sema.mod)}); | 6650 | std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(mod)}); |
| 6670 | }; | 6651 | }; |
| 6671 | | 6652 | |
| 6672 | const func_ty_info = mod.typeToFunc(func_ty).?; | 6653 | const func_ty_info = mod.typeToFunc(func_ty).?; |
| ... | @@ -6942,7 +6923,7 @@ fn analyzeCall( | ... | @@ -6942,7 +6923,7 @@ fn analyzeCall( |
| 6942 | ) catch |err| switch (err) { | 6923 | ) catch |err| switch (err) { |
| 6943 | error.NeededSourceLocation => { | 6924 | error.NeededSourceLocation => { |
| 6944 | _ = sema.inst_map.remove(inst); | 6925 | _ = sema.inst_map.remove(inst); |
| 6945 | const decl = sema.mod.declPtr(block.src_decl); | 6926 | const decl = mod.declPtr(block.src_decl); |
| 6946 | try sema.analyzeInlineCallArg( | 6927 | try sema.analyzeInlineCallArg( |
| 6947 | block, | 6928 | block, |
| 6948 | &child_block, | 6929 | &child_block, |
| ... | @@ -7111,7 +7092,7 @@ fn analyzeCall( | ... | @@ -7111,7 +7092,7 @@ fn analyzeCall( |
| 7111 | opts, | 7092 | opts, |
| 7112 | ) catch |err| switch (err) { | 7093 | ) catch |err| switch (err) { |
| 7113 | error.NeededSourceLocation => { | 7094 | error.NeededSourceLocation => { |
| 7114 | const decl = sema.mod.declPtr(block.src_decl); | 7095 | const decl = mod.declPtr(block.src_decl); |
| 7115 | _ = try sema.analyzeCallArg( | 7096 | _ = try sema.analyzeCallArg( |
| 7116 | block, | 7097 | block, |
| 7117 | mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src), | 7098 | mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src), |
| ... | @@ -7126,7 +7107,7 @@ fn analyzeCall( | ... | @@ -7126,7 +7107,7 @@ fn analyzeCall( |
| 7126 | } else { | 7107 | } else { |
| 7127 | args[i] = sema.coerceVarArgParam(block, uncasted_arg, .unneeded) catch |err| switch (err) { | 7108 | args[i] = sema.coerceVarArgParam(block, uncasted_arg, .unneeded) catch |err| switch (err) { |
| 7128 | error.NeededSourceLocation => { | 7109 | error.NeededSourceLocation => { |
| 7129 | const decl = sema.mod.declPtr(block.src_decl); | 7110 | const decl = mod.declPtr(block.src_decl); |
| 7130 | _ = try sema.coerceVarArgParam( | 7111 | _ = try sema.coerceVarArgParam( |
| 7131 | block, | 7112 | block, |
| 7132 | uncasted_arg, | 7113 | uncasted_arg, |
| ... | @@ -7148,7 +7129,7 @@ fn analyzeCall( | ... | @@ -7148,7 +7129,7 @@ fn analyzeCall( |
| 7148 | | 7129 | |
| 7149 | if (try sema.resolveMaybeUndefVal(func)) |func_val| { | 7130 | if (try sema.resolveMaybeUndefVal(func)) |func_val| { |
| 7150 | if (mod.intern_pool.indexToFunc(func_val.toIntern()).unwrap()) |func_index| { | 7131 | if (mod.intern_pool.indexToFunc(func_val.toIntern()).unwrap()) |func_index| { |
| 7151 | try sema.mod.ensureFuncBodyAnalysisQueued(func_index); | 7132 | try mod.ensureFuncBodyAnalysisQueued(func_index); |
| 7152 | } | 7133 | } |
| 7153 | } | 7134 | } |
| 7154 | | 7135 | |
| ... | @@ -7201,17 +7182,18 @@ fn analyzeCall( | ... | @@ -7201,17 +7182,18 @@ fn analyzeCall( |
| 7201 | } | 7182 | } |
| 7202 | | 7183 | |
| 7203 | fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Type, result: Air.Inst.Ref) !Air.Inst.Ref { | 7184 | fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Type, result: Air.Inst.Ref) !Air.Inst.Ref { |
| 7204 | const target = sema.mod.getTarget(); | 7185 | const mod = sema.mod; |
| 7205 | const backend = sema.mod.comp.getZigBackend(); | 7186 | const target = mod.getTarget(); |
| | 7187 | const backend = mod.comp.getZigBackend(); |
| 7206 | if (!target_util.supportsTailCall(target, backend)) { | 7188 | if (!target_util.supportsTailCall(target, backend)) { |
| 7207 | return sema.fail(block, call_src, "unable to perform tail call: compiler backend '{s}' does not support tail calls on target architecture '{s}' with the selected CPU feature flags", .{ | 7189 | return sema.fail(block, call_src, "unable to perform tail call: compiler backend '{s}' does not support tail calls on target architecture '{s}' with the selected CPU feature flags", .{ |
| 7208 | @tagName(backend), @tagName(target.cpu.arch), | 7190 | @tagName(backend), @tagName(target.cpu.arch), |
| 7209 | }); | 7191 | }); |
| 7210 | } | 7192 | } |
| 7211 | const func_decl = sema.mod.declPtr(sema.owner_func.?.owner_decl); | 7193 | const func_decl = mod.declPtr(sema.owner_func.?.owner_decl); |
| 7212 | if (!func_ty.eql(func_decl.ty, sema.mod)) { | 7194 | if (!func_ty.eql(func_decl.ty, mod)) { |
| 7213 | return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{ | 7195 | return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{ |
| 7214 | func_ty.fmt(sema.mod), func_decl.ty.fmt(sema.mod), | 7196 | func_ty.fmt(mod), func_decl.ty.fmt(mod), |
| 7215 | }); | 7197 | }); |
| 7216 | } | 7198 | } |
| 7217 | _ = try block.addUnOp(.ret, result); | 7199 | _ = try block.addUnOp(.ret, result); |
| ... | @@ -7404,10 +7386,9 @@ fn instantiateGenericCall( | ... | @@ -7404,10 +7386,9 @@ fn instantiateGenericCall( |
| 7404 | ) CompileError!Air.Inst.Ref { | 7386 | ) CompileError!Air.Inst.Ref { |
| 7405 | const mod = sema.mod; | 7387 | const mod = sema.mod; |
| 7406 | const gpa = sema.gpa; | 7388 | const gpa = sema.gpa; |
| 7407 | const ip = &mod.intern_pool; | | |
| 7408 | | 7389 | |
| 7409 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); | 7390 | const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known"); |
| 7410 | const module_fn_index = switch (ip.indexToKey(func_val.toIntern())) { | 7391 | const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7411 | .func => |function| function.index, | 7392 | .func => |function| function.index, |
| 7412 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?, | 7393 | .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?, |
| 7413 | else => unreachable, | 7394 | else => unreachable, |
| ... | @@ -7467,7 +7448,7 @@ fn instantiateGenericCall( | ... | @@ -7467,7 +7448,7 @@ fn instantiateGenericCall( |
| 7467 | if (is_comptime) { | 7448 | if (is_comptime) { |
| 7468 | const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[arg_i]) catch |err| switch (err) { | 7449 | const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[arg_i]) catch |err| switch (err) { |
| 7469 | error.NeededSourceLocation => { | 7450 | error.NeededSourceLocation => { |
| 7470 | const decl = sema.mod.declPtr(block.src_decl); | 7451 | const decl = mod.declPtr(block.src_decl); |
| 7471 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); | 7452 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); |
| 7472 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[arg_i]); | 7453 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[arg_i]); |
| 7473 | unreachable; | 7454 | unreachable; |
| ... | @@ -7491,7 +7472,7 @@ fn instantiateGenericCall( | ... | @@ -7491,7 +7472,7 @@ fn instantiateGenericCall( |
| 7491 | }; | 7472 | }; |
| 7492 | const casted_arg = sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], .unneeded) catch |err| switch (err) { | 7473 | const casted_arg = sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], .unneeded) catch |err| switch (err) { |
| 7493 | error.NeededSourceLocation => { | 7474 | error.NeededSourceLocation => { |
| 7494 | const decl = sema.mod.declPtr(block.src_decl); | 7475 | const decl = mod.declPtr(block.src_decl); |
| 7495 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); | 7476 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); |
| 7496 | _ = try sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], arg_src); | 7477 | _ = try sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], arg_src); |
| 7497 | unreachable; | 7478 | unreachable; |
| ... | @@ -7500,7 +7481,7 @@ fn instantiateGenericCall( | ... | @@ -7500,7 +7481,7 @@ fn instantiateGenericCall( |
| 7500 | }; | 7481 | }; |
| 7501 | const casted_arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, casted_arg) catch |err| switch (err) { | 7482 | const casted_arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, casted_arg) catch |err| switch (err) { |
| 7502 | error.NeededSourceLocation => { | 7483 | error.NeededSourceLocation => { |
| 7503 | const decl = sema.mod.declPtr(block.src_decl); | 7484 | const decl = mod.declPtr(block.src_decl); |
| 7504 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); | 7485 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); |
| 7505 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, casted_arg); | 7486 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, casted_arg); |
| 7506 | unreachable; | 7487 | unreachable; |
| ... | @@ -7540,12 +7521,9 @@ fn instantiateGenericCall( | ... | @@ -7540,12 +7521,9 @@ fn instantiateGenericCall( |
| 7540 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); | 7521 | const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope); |
| 7541 | const new_decl = mod.declPtr(new_decl_index); | 7522 | const new_decl = mod.declPtr(new_decl_index); |
| 7542 | // TODO better names for generic function instantiations | 7523 | // TODO better names for generic function instantiations |
| 7543 | // The ensureUnusedCapacity here protects against fn_owner_decl.name slice being | 7524 | const decl_name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}__anon_{d}", .{ |
| 7544 | // reallocated during getOrPutStringFmt. | 7525 | fn_owner_decl.name.fmt(&mod.intern_pool), @enumToInt(new_decl_index), |
| 7545 | try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(fn_owner_decl.name).len + 20); | 7526 | }); |
| 7546 | const decl_name = ip.getOrPutStringFmt(gpa, "{s}__anon_{d}", .{ | | |
| 7547 | ip.stringToSlice(fn_owner_decl.name), @enumToInt(new_decl_index), | | |
| 7548 | }) catch unreachable; | | |
| 7549 | new_decl.name = decl_name; | 7527 | new_decl.name = decl_name; |
| 7550 | new_decl.src_line = fn_owner_decl.src_line; | 7528 | new_decl.src_line = fn_owner_decl.src_line; |
| 7551 | new_decl.is_pub = fn_owner_decl.is_pub; | 7529 | new_decl.is_pub = fn_owner_decl.is_pub; |
| ... | @@ -7634,7 +7612,7 @@ fn instantiateGenericCall( | ... | @@ -7634,7 +7612,7 @@ fn instantiateGenericCall( |
| 7634 | &runtime_i, | 7612 | &runtime_i, |
| 7635 | ) catch |err| switch (err) { | 7613 | ) catch |err| switch (err) { |
| 7636 | error.NeededSourceLocation => { | 7614 | error.NeededSourceLocation => { |
| 7637 | const decl = sema.mod.declPtr(block.src_decl); | 7615 | const decl = mod.declPtr(block.src_decl); |
| 7638 | _ = try sema.analyzeGenericCallArg( | 7616 | _ = try sema.analyzeGenericCallArg( |
| 7639 | block, | 7617 | block, |
| 7640 | mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src), | 7618 | mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src), |
| ... | @@ -7660,7 +7638,7 @@ fn instantiateGenericCall( | ... | @@ -7660,7 +7638,7 @@ fn instantiateGenericCall( |
| 7660 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; | 7638 | sema.owner_func.?.calls_or_awaits_errorable_fn = true; |
| 7661 | } | 7639 | } |
| 7662 | | 7640 | |
| 7663 | try sema.mod.ensureFuncBodyAnalysisQueued(callee_index); | 7641 | try mod.ensureFuncBodyAnalysisQueued(callee_index); |
| 7664 | | 7642 | |
| 7665 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len + | 7643 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len + |
| 7666 | runtime_args_len); | 7644 | runtime_args_len); |
| ... | @@ -7788,7 +7766,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7788,7 +7766,7 @@ fn resolveGenericInstantiationType( |
| 7788 | if (try sema.typeRequiresComptime(arg_ty)) { | 7766 | if (try sema.typeRequiresComptime(arg_ty)) { |
| 7789 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) { | 7767 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) { |
| 7790 | error.NeededSourceLocation => { | 7768 | error.NeededSourceLocation => { |
| 7791 | const decl = sema.mod.declPtr(block.src_decl); | 7769 | const decl = mod.declPtr(block.src_decl); |
| 7792 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); | 7770 | const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src); |
| 7793 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); | 7771 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); |
| 7794 | unreachable; | 7772 | unreachable; |
| ... | @@ -7981,9 +7959,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -7981,9 +7959,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 7981 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 7959 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; |
| 7982 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); | 7960 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 7983 | if (child_type.zigTypeTag(mod) == .Opaque) { | 7961 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| 7984 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(sema.mod)}); | 7962 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)}); |
| 7985 | } else if (child_type.zigTypeTag(mod) == .Null) { | 7963 | } else if (child_type.zigTypeTag(mod) == .Null) { |
| 7986 | return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(sema.mod)}); | 7964 | return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(mod)}); |
| 7987 | } | 7965 | } |
| 7988 | const opt_type = try Type.optional(sema.arena, child_type, mod); | 7966 | const opt_type = try Type.optional(sema.arena, child_type, mod); |
| 7989 | | 7967 | |
| ... | @@ -8059,7 +8037,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8059,7 +8037,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8059 | fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void { | 8037 | fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void { |
| 8060 | const mod = sema.mod; | 8038 | const mod = sema.mod; |
| 8061 | if (elem_type.zigTypeTag(mod) == .Opaque) { | 8039 | if (elem_type.zigTypeTag(mod) == .Opaque) { |
| 8062 | return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(sema.mod)}); | 8040 | return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(mod)}); |
| 8063 | } else if (elem_type.zigTypeTag(mod) == .NoReturn) { | 8041 | } else if (elem_type.zigTypeTag(mod) == .NoReturn) { |
| 8064 | return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{}); | 8042 | return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{}); |
| 8065 | } | 8043 | } |
| ... | @@ -8095,7 +8073,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8095,7 +8073,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8095 | | 8073 | |
| 8096 | if (error_set.zigTypeTag(mod) != .ErrorSet) { | 8074 | if (error_set.zigTypeTag(mod) != .ErrorSet) { |
| 8097 | return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{ | 8075 | return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{ |
| 8098 | error_set.fmt(sema.mod), | 8076 | error_set.fmt(mod), |
| 8099 | }); | 8077 | }); |
| 8100 | } | 8078 | } |
| 8101 | try sema.validateErrorUnionPayloadType(block, payload, rhs_src); | 8079 | try sema.validateErrorUnionPayloadType(block, payload, rhs_src); |
| ... | @@ -8107,11 +8085,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p | ... | @@ -8107,11 +8085,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p |
| 8107 | const mod = sema.mod; | 8085 | const mod = sema.mod; |
| 8108 | if (payload_ty.zigTypeTag(mod) == .Opaque) { | 8086 | if (payload_ty.zigTypeTag(mod) == .Opaque) { |
| 8109 | return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{ | 8087 | return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{ |
| 8110 | payload_ty.fmt(sema.mod), | 8088 | payload_ty.fmt(mod), |
| 8111 | }); | 8089 | }); |
| 8112 | } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) { | 8090 | } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) { |
| 8113 | return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{ | 8091 | return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{ |
| 8114 | payload_ty.fmt(sema.mod), | 8092 | payload_ty.fmt(mod), |
| 8115 | }); | 8093 | }); |
| 8116 | } | 8094 | } |
| 8117 | } | 8095 | } |
| ... | @@ -8123,7 +8101,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -8123,7 +8101,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 8123 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 8101 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 8124 | _ = try mod.getErrorValue(name); | 8102 | _ = try mod.getErrorValue(name); |
| 8125 | // Create an error set type with only this error value, and return the value. | 8103 | // Create an error set type with only this error value, and return the value. |
| 8126 | const error_set_type = try mod.singleErrorSetTypeNts(name); | 8104 | const error_set_type = try mod.singleErrorSetType(name); |
| 8127 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 8105 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 8128 | .ty = error_set_type.toIntern(), | 8106 | .ty = error_set_type.toIntern(), |
| 8129 | .name = name, | 8107 | .name = name, |
| ... | @@ -8231,9 +8209,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8231,9 +8209,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8231 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); | 8209 | const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs); |
| 8232 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); | 8210 | const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs); |
| 8233 | if (lhs_ty.zigTypeTag(mod) != .ErrorSet) | 8211 | if (lhs_ty.zigTypeTag(mod) != .ErrorSet) |
| 8234 | return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(sema.mod)}); | 8212 | return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(mod)}); |
| 8235 | if (rhs_ty.zigTypeTag(mod) != .ErrorSet) | 8213 | if (rhs_ty.zigTypeTag(mod) != .ErrorSet) |
| 8236 | return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)}); | 8214 | return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(mod)}); |
| 8237 | | 8215 | |
| 8238 | // Anything merged with anyerror is anyerror. | 8216 | // Anything merged with anyerror is anyerror. |
| 8239 | if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) { | 8217 | if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) { |
| ... | @@ -8296,7 +8274,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8296,7 +8274,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8296 | }, | 8274 | }, |
| 8297 | else => { | 8275 | else => { |
| 8298 | return sema.fail(block, operand_src, "expected enum or tagged union, found '{}'", .{ | 8276 | return sema.fail(block, operand_src, "expected enum or tagged union, found '{}'", .{ |
| 8299 | operand_ty.fmt(sema.mod), | 8277 | operand_ty.fmt(mod), |
| 8300 | }); | 8278 | }); |
| 8301 | }, | 8279 | }, |
| 8302 | }; | 8280 | }; |
| ... | @@ -8328,7 +8306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8328,7 +8306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8328 | const operand = try sema.resolveInst(extra.rhs); | 8306 | const operand = try sema.resolveInst(extra.rhs); |
| 8329 | | 8307 | |
| 8330 | if (dest_ty.zigTypeTag(mod) != .Enum) { | 8308 | if (dest_ty.zigTypeTag(mod) != .Enum) { |
| 8331 | return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(sema.mod)}); | 8309 | return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(mod)}); |
| 8332 | } | 8310 | } |
| 8333 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); | 8311 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); |
| 8334 | | 8312 | |
| ... | @@ -8343,7 +8321,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8343,7 +8321,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8343 | block, | 8321 | block, |
| 8344 | src, | 8322 | src, |
| 8345 | "int value '{}' out of range of non-exhaustive enum '{}'", | 8323 | "int value '{}' out of range of non-exhaustive enum '{}'", |
| 8346 | .{ int_val.fmtValue(sema.typeOf(operand), sema.mod), dest_ty.fmt(sema.mod) }, | 8324 | .{ int_val.fmtValue(sema.typeOf(operand), mod), dest_ty.fmt(mod) }, |
| 8347 | ); | 8325 | ); |
| 8348 | errdefer msg.destroy(sema.gpa); | 8326 | errdefer msg.destroy(sema.gpa); |
| 8349 | try sema.addDeclaredHereNote(msg, dest_ty); | 8327 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | @@ -8360,7 +8338,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8360,7 +8338,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8360 | block, | 8338 | block, |
| 8361 | src, | 8339 | src, |
| 8362 | "enum '{}' has no tag with value '{}'", | 8340 | "enum '{}' has no tag with value '{}'", |
| 8363 | .{ dest_ty.fmt(sema.mod), int_val.fmtValue(sema.typeOf(operand), sema.mod) }, | 8341 | .{ dest_ty.fmt(mod), int_val.fmtValue(sema.typeOf(operand), mod) }, |
| 8364 | ); | 8342 | ); |
| 8365 | errdefer msg.destroy(sema.gpa); | 8343 | errdefer msg.destroy(sema.gpa); |
| 8366 | try sema.addDeclaredHereNote(msg, dest_ty); | 8344 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | @@ -8383,7 +8361,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8383,7 +8361,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8383 | try sema.requireRuntimeBlock(block, src, operand_src); | 8361 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 8384 | const result = try block.addTyOp(.intcast, dest_ty, operand); | 8362 | const result = try block.addTyOp(.intcast, dest_ty, operand); |
| 8385 | if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and | 8363 | if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and |
| 8386 | sema.mod.backendSupportsFeature(.is_named_enum_value)) | 8364 | mod.backendSupportsFeature(.is_named_enum_value)) |
| 8387 | { | 8365 | { |
| 8388 | const ok = try block.addUnOp(.is_named_enum_value, result); | 8366 | const ok = try block.addUnOp(.is_named_enum_value, result); |
| 8389 | try sema.addSafetyCheck(block, ok, .invalid_enum_value); | 8367 | try sema.addSafetyCheck(block, ok, .invalid_enum_value); |
| ... | @@ -8422,11 +8400,11 @@ fn analyzeOptionalPayloadPtr( | ... | @@ -8422,11 +8400,11 @@ fn analyzeOptionalPayloadPtr( |
| 8422 | | 8400 | |
| 8423 | const opt_type = optional_ptr_ty.childType(mod); | 8401 | const opt_type = optional_ptr_ty.childType(mod); |
| 8424 | if (opt_type.zigTypeTag(mod) != .Optional) { | 8402 | if (opt_type.zigTypeTag(mod) != .Optional) { |
| 8425 | return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(sema.mod)}); | 8403 | return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(mod)}); |
| 8426 | } | 8404 | } |
| 8427 | | 8405 | |
| 8428 | const child_type = opt_type.optionalChild(mod); | 8406 | const child_type = opt_type.optionalChild(mod); |
| 8429 | const child_pointer = try Type.ptr(sema.arena, sema.mod, .{ | 8407 | const child_pointer = try Type.ptr(sema.arena, mod, .{ |
| 8430 | .pointee_type = child_type, | 8408 | .pointee_type = child_type, |
| 8431 | .mutable = !optional_ptr_ty.isConstPtr(mod), | 8409 | .mutable = !optional_ptr_ty.isConstPtr(mod), |
| 8432 | .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod), | 8410 | .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod), |
| ... | @@ -8493,7 +8471,7 @@ fn zirOptionalPayload( | ... | @@ -8493,7 +8471,7 @@ fn zirOptionalPayload( |
| 8493 | // TODO https://github.com/ziglang/zig/issues/6597 | 8471 | // TODO https://github.com/ziglang/zig/issues/6597 |
| 8494 | if (true) break :t operand_ty; | 8472 | if (true) break :t operand_ty; |
| 8495 | const ptr_info = operand_ty.ptrInfo(mod); | 8473 | const ptr_info = operand_ty.ptrInfo(mod); |
| 8496 | break :t try Type.ptr(sema.arena, sema.mod, .{ | 8474 | break :t try Type.ptr(sema.arena, mod, .{ |
| 8497 | .pointee_type = ptr_info.pointee_type, | 8475 | .pointee_type = ptr_info.pointee_type, |
| 8498 | .@"align" = ptr_info.@"align", | 8476 | .@"align" = ptr_info.@"align", |
| 8499 | .@"addrspace" = ptr_info.@"addrspace", | 8477 | .@"addrspace" = ptr_info.@"addrspace", |
| ... | @@ -8538,7 +8516,7 @@ fn zirErrUnionPayload( | ... | @@ -8538,7 +8516,7 @@ fn zirErrUnionPayload( |
| 8538 | const err_union_ty = sema.typeOf(operand); | 8516 | const err_union_ty = sema.typeOf(operand); |
| 8539 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { | 8517 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| 8540 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{ | 8518 | return sema.fail(block, operand_src, "expected error union type, found '{}'", .{ |
| 8541 | err_union_ty.fmt(sema.mod), | 8519 | err_union_ty.fmt(mod), |
| 8542 | }); | 8520 | }); |
| 8543 | } | 8521 | } |
| 8544 | return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); | 8522 | return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false); |
| ... | @@ -8556,8 +8534,8 @@ fn analyzeErrUnionPayload( | ... | @@ -8556,8 +8534,8 @@ fn analyzeErrUnionPayload( |
| 8556 | const mod = sema.mod; | 8534 | const mod = sema.mod; |
| 8557 | const payload_ty = err_union_ty.errorUnionPayload(mod); | 8535 | const payload_ty = err_union_ty.errorUnionPayload(mod); |
| 8558 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { | 8536 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { |
| 8559 | if (val.getError(mod)) |name| { | 8537 | if (val.getErrorName(mod).unwrap()) |name| { |
| 8560 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); | 8538 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 8561 | } | 8539 | } |
| 8562 | return sema.addConstant( | 8540 | return sema.addConstant( |
| 8563 | payload_ty, | 8541 | payload_ty, |
| ... | @@ -8607,13 +8585,13 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -8607,13 +8585,13 @@ fn analyzeErrUnionPayloadPtr( |
| 8607 | | 8585 | |
| 8608 | if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) { | 8586 | if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) { |
| 8609 | return sema.fail(block, src, "expected error union type, found '{}'", .{ | 8587 | return sema.fail(block, src, "expected error union type, found '{}'", .{ |
| 8610 | operand_ty.childType(mod).fmt(sema.mod), | 8588 | operand_ty.childType(mod).fmt(mod), |
| 8611 | }); | 8589 | }); |
| 8612 | } | 8590 | } |
| 8613 | | 8591 | |
| 8614 | const err_union_ty = operand_ty.childType(mod); | 8592 | const err_union_ty = operand_ty.childType(mod); |
| 8615 | const payload_ty = err_union_ty.errorUnionPayload(mod); | 8593 | const payload_ty = err_union_ty.errorUnionPayload(mod); |
| 8616 | const operand_pointer_ty = try Type.ptr(sema.arena, sema.mod, .{ | 8594 | const operand_pointer_ty = try Type.ptr(sema.arena, mod, .{ |
| 8617 | .pointee_type = payload_ty, | 8595 | .pointee_type = payload_ty, |
| 8618 | .mutable = !operand_ty.isConstPtr(mod), | 8596 | .mutable = !operand_ty.isConstPtr(mod), |
| 8619 | .@"addrspace" = operand_ty.ptrAddressSpace(mod), | 8597 | .@"addrspace" = operand_ty.ptrAddressSpace(mod), |
| ... | @@ -8634,8 +8612,8 @@ fn analyzeErrUnionPayloadPtr( | ... | @@ -8634,8 +8612,8 @@ fn analyzeErrUnionPayloadPtr( |
| 8634 | } })).toValue()); | 8612 | } })).toValue()); |
| 8635 | } | 8613 | } |
| 8636 | if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| { | 8614 | if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| { |
| 8637 | if (val.getError(mod)) |name| { | 8615 | if (val.getErrorName(mod).unwrap()) |name| { |
| 8638 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); | 8616 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 8639 | } | 8617 | } |
| 8640 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ | 8618 | return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{ |
| 8641 | .ty = operand_pointer_ty.toIntern(), | 8619 | .ty = operand_pointer_ty.toIntern(), |
| ... | @@ -8676,7 +8654,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air | ... | @@ -8676,7 +8654,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air |
| 8676 | const operand_ty = sema.typeOf(operand); | 8654 | const operand_ty = sema.typeOf(operand); |
| 8677 | if (operand_ty.zigTypeTag(mod) != .ErrorUnion) { | 8655 | if (operand_ty.zigTypeTag(mod) != .ErrorUnion) { |
| 8678 | return sema.fail(block, src, "expected error union type, found '{}'", .{ | 8656 | return sema.fail(block, src, "expected error union type, found '{}'", .{ |
| 8679 | operand_ty.fmt(sema.mod), | 8657 | operand_ty.fmt(mod), |
| 8680 | }); | 8658 | }); |
| 8681 | } | 8659 | } |
| 8682 | | 8660 | |
| ... | @@ -8707,7 +8685,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8707,7 +8685,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8707 | | 8685 | |
| 8708 | if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) { | 8686 | if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) { |
| 8709 | return sema.fail(block, src, "expected error union type, found '{}'", .{ | 8687 | return sema.fail(block, src, "expected error union type, found '{}'", .{ |
| 8710 | operand_ty.childType(mod).fmt(sema.mod), | 8688 | operand_ty.childType(mod).fmt(mod), |
| 8711 | }); | 8689 | }); |
| 8712 | } | 8690 | } |
| 8713 | | 8691 | |
| ... | @@ -8715,7 +8693,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -8715,7 +8693,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8715 | | 8693 | |
| 8716 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { | 8694 | if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| { |
| 8717 | if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| { | 8695 | if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| { |
| 8718 | assert(val.getError(mod) != null); | 8696 | assert(val.getErrorName(mod) != .none); |
| 8719 | return sema.addConstant(result_ty, val); | 8697 | return sema.addConstant(result_ty, val); |
| 8720 | } | 8698 | } |
| 8721 | } | 8699 | } |
| ... | @@ -8968,7 +8946,7 @@ fn funcCommon( | ... | @@ -8968,7 +8946,7 @@ fn funcCommon( |
| 8968 | }; | 8946 | }; |
| 8969 | errdefer if (destroy_fn_on_error) mod.destroyFunc(new_func_index); | 8947 | errdefer if (destroy_fn_on_error) mod.destroyFunc(new_func_index); |
| 8970 | | 8948 | |
| 8971 | const target = sema.mod.getTarget(); | 8949 | const target = mod.getTarget(); |
| 8972 | const fn_ty: Type = fn_ty: { | 8950 | const fn_ty: Type = fn_ty: { |
| 8973 | // In the case of generic calling convention, or generic alignment, we use | 8951 | // In the case of generic calling convention, or generic alignment, we use |
| 8974 | // default values which are only meaningful for the generic function, *not* | 8952 | // default values which are only meaningful for the generic function, *not* |
| ... | @@ -8995,7 +8973,7 @@ fn funcCommon( | ... | @@ -8995,7 +8973,7 @@ fn funcCommon( |
| 8995 | is_noalias, | 8973 | is_noalias, |
| 8996 | ) catch |err| switch (err) { | 8974 | ) catch |err| switch (err) { |
| 8997 | error.NeededSourceLocation => { | 8975 | error.NeededSourceLocation => { |
| 8998 | const decl = sema.mod.declPtr(block.src_decl); | 8976 | const decl = mod.declPtr(block.src_decl); |
| 8999 | try sema.analyzeParameter( | 8977 | try sema.analyzeParameter( |
| 9000 | block, | 8978 | block, |
| 9001 | Module.paramSrc(src_node_offset, mod, decl, i), | 8979 | Module.paramSrc(src_node_offset, mod, decl, i), |
| ... | @@ -9040,7 +9018,7 @@ fn funcCommon( | ... | @@ -9040,7 +9018,7 @@ fn funcCommon( |
| 9040 | const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else ""; | 9018 | const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else ""; |
| 9041 | const msg = msg: { | 9019 | const msg = msg: { |
| 9042 | const msg = try sema.errMsg(block, ret_ty_src, "{s}return type '{}' not allowed", .{ | 9020 | const msg = try sema.errMsg(block, ret_ty_src, "{s}return type '{}' not allowed", .{ |
| 9043 | opaque_str, return_type.fmt(sema.mod), | 9021 | opaque_str, return_type.fmt(mod), |
| 9044 | }); | 9022 | }); |
| 9045 | errdefer msg.destroy(gpa); | 9023 | errdefer msg.destroy(gpa); |
| 9046 | | 9024 | |
| ... | @@ -9054,11 +9032,11 @@ fn funcCommon( | ... | @@ -9054,11 +9032,11 @@ fn funcCommon( |
| 9054 | { | 9032 | { |
| 9055 | const msg = msg: { | 9033 | const msg = msg: { |
| 9056 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ | 9034 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ |
| 9057 | return_type.fmt(sema.mod), @tagName(cc_resolved), | 9035 | return_type.fmt(mod), @tagName(cc_resolved), |
| 9058 | }); | 9036 | }); |
| 9059 | errdefer msg.destroy(gpa); | 9037 | errdefer msg.destroy(gpa); |
| 9060 | | 9038 | |
| 9061 | const src_decl = sema.mod.declPtr(block.src_decl); | 9039 | const src_decl = mod.declPtr(block.src_decl); |
| 9062 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty); | 9040 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty); |
| 9063 | | 9041 | |
| 9064 | try sema.addDeclaredHereNote(msg, return_type); | 9042 | try sema.addDeclaredHereNote(msg, return_type); |
| ... | @@ -9077,7 +9055,7 @@ fn funcCommon( | ... | @@ -9077,7 +9055,7 @@ fn funcCommon( |
| 9077 | block, | 9055 | block, |
| 9078 | ret_ty_src, | 9056 | ret_ty_src, |
| 9079 | "function with comptime-only return type '{}' requires all parameters to be comptime", | 9057 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 9080 | .{return_type.fmt(sema.mod)}, | 9058 | .{return_type.fmt(mod)}, |
| 9081 | ); | 9059 | ); |
| 9082 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type); | 9060 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type); |
| 9083 | | 9061 | |
| ... | @@ -9102,7 +9080,7 @@ fn funcCommon( | ... | @@ -9102,7 +9080,7 @@ fn funcCommon( |
| 9102 | return sema.failWithOwnedErrorMsg(msg); | 9080 | return sema.failWithOwnedErrorMsg(msg); |
| 9103 | } | 9081 | } |
| 9104 | | 9082 | |
| 9105 | const arch = sema.mod.getTarget().cpu.arch; | 9083 | const arch = mod.getTarget().cpu.arch; |
| 9106 | if (switch (cc_resolved) { | 9084 | if (switch (cc_resolved) { |
| 9107 | .Unspecified, .C, .Naked, .Async, .Inline => null, | 9085 | .Unspecified, .C, .Naked, .Async, .Inline => null, |
| 9108 | .Interrupt => switch (arch) { | 9086 | .Interrupt => switch (arch) { |
| ... | @@ -9542,7 +9520,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -9542,7 +9520,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9542 | const ptr = try sema.resolveInst(inst_data.operand); | 9520 | const ptr = try sema.resolveInst(inst_data.operand); |
| 9543 | const ptr_ty = sema.typeOf(ptr); | 9521 | const ptr_ty = sema.typeOf(ptr); |
| 9544 | if (!ptr_ty.isPtrAtRuntime(mod)) { | 9522 | if (!ptr_ty.isPtrAtRuntime(mod)) { |
| 9545 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}); | 9523 | return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(mod)}); |
| 9546 | } | 9524 | } |
| 9547 | if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| { | 9525 | if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| { |
| 9548 | return sema.addConstant( | 9526 | return sema.addConstant( |
| ... | @@ -9797,14 +9775,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9797,14 +9775,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9797 | .Type, | 9775 | .Type, |
| 9798 | .Undefined, | 9776 | .Undefined, |
| 9799 | .Void, | 9777 | .Void, |
| 9800 | => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}), | 9778 | => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}), |
| 9801 | | 9779 | |
| 9802 | .Enum => { | 9780 | .Enum => { |
| 9803 | const msg = msg: { | 9781 | const msg = msg: { |
| 9804 | const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}); | 9782 | const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 9805 | errdefer msg.destroy(sema.gpa); | 9783 | errdefer msg.destroy(sema.gpa); |
| 9806 | switch (operand_ty.zigTypeTag(mod)) { | 9784 | switch (operand_ty.zigTypeTag(mod)) { |
| 9807 | .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToEnum to cast from '{}'", .{operand_ty.fmt(sema.mod)}), | 9785 | .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToEnum to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 9808 | else => {}, | 9786 | else => {}, |
| 9809 | } | 9787 | } |
| 9810 | | 9788 | |
| ... | @@ -9815,11 +9793,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9815,11 +9793,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9815 | | 9793 | |
| 9816 | .Pointer => { | 9794 | .Pointer => { |
| 9817 | const msg = msg: { | 9795 | const msg = msg: { |
| 9818 | const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}); | 9796 | const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 9819 | errdefer msg.destroy(sema.gpa); | 9797 | errdefer msg.destroy(sema.gpa); |
| 9820 | switch (operand_ty.zigTypeTag(mod)) { | 9798 | switch (operand_ty.zigTypeTag(mod)) { |
| 9821 | .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToPtr to cast from '{}'", .{operand_ty.fmt(sema.mod)}), | 9799 | .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToPtr to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 9822 | .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(sema.mod)}), | 9800 | .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 9823 | else => {}, | 9801 | else => {}, |
| 9824 | } | 9802 | } |
| 9825 | | 9803 | |
| ... | @@ -9834,7 +9812,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9834,7 +9812,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9834 | else => unreachable, | 9812 | else => unreachable, |
| 9835 | }; | 9813 | }; |
| 9836 | return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{ | 9814 | return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{ |
| 9837 | dest_ty.fmt(sema.mod), container, | 9815 | dest_ty.fmt(mod), container, |
| 9838 | }); | 9816 | }); |
| 9839 | }, | 9817 | }, |
| 9840 | | 9818 | |
| ... | @@ -9861,14 +9839,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9861,14 +9839,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9861 | .Type, | 9839 | .Type, |
| 9862 | .Undefined, | 9840 | .Undefined, |
| 9863 | .Void, | 9841 | .Void, |
| 9864 | => return sema.fail(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)}), | 9842 | => return sema.fail(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}), |
| 9865 | | 9843 | |
| 9866 | .Enum => { | 9844 | .Enum => { |
| 9867 | const msg = msg: { | 9845 | const msg = msg: { |
| 9868 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)}); | 9846 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); |
| 9869 | errdefer msg.destroy(sema.gpa); | 9847 | errdefer msg.destroy(sema.gpa); |
| 9870 | switch (dest_ty.zigTypeTag(mod)) { | 9848 | switch (dest_ty.zigTypeTag(mod)) { |
| 9871 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @enumToInt to cast to '{}'", .{dest_ty.fmt(sema.mod)}), | 9849 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @enumToInt to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 9872 | else => {}, | 9850 | else => {}, |
| 9873 | } | 9851 | } |
| 9874 | | 9852 | |
| ... | @@ -9878,11 +9856,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9878,11 +9856,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9878 | }, | 9856 | }, |
| 9879 | .Pointer => { | 9857 | .Pointer => { |
| 9880 | const msg = msg: { | 9858 | const msg = msg: { |
| 9881 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)}); | 9859 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); |
| 9882 | errdefer msg.destroy(sema.gpa); | 9860 | errdefer msg.destroy(sema.gpa); |
| 9883 | switch (dest_ty.zigTypeTag(mod)) { | 9861 | switch (dest_ty.zigTypeTag(mod)) { |
| 9884 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @ptrToInt to cast to '{}'", .{dest_ty.fmt(sema.mod)}), | 9862 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @ptrToInt to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 9885 | .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(sema.mod)}), | 9863 | .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 9886 | else => {}, | 9864 | else => {}, |
| 9887 | } | 9865 | } |
| 9888 | | 9866 | |
| ... | @@ -9897,7 +9875,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9897,7 +9875,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9897 | else => unreachable, | 9875 | else => unreachable, |
| 9898 | }; | 9876 | }; |
| 9899 | return sema.fail(block, operand_src, "cannot @bitCast from '{}'; {s} does not have a guaranteed in-memory layout", .{ | 9877 | return sema.fail(block, operand_src, "cannot @bitCast from '{}'; {s} does not have a guaranteed in-memory layout", .{ |
| 9900 | operand_ty.fmt(sema.mod), container, | 9878 | operand_ty.fmt(mod), container, |
| 9901 | }); | 9879 | }); |
| 9902 | }, | 9880 | }, |
| 9903 | | 9881 | |
| ... | @@ -9924,7 +9902,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -9924,7 +9902,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9924 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); | 9902 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 9925 | const operand = try sema.resolveInst(extra.rhs); | 9903 | const operand = try sema.resolveInst(extra.rhs); |
| 9926 | | 9904 | |
| 9927 | const target = sema.mod.getTarget(); | 9905 | const target = mod.getTarget(); |
| 9928 | const dest_is_comptime_float = switch (dest_ty.zigTypeTag(mod)) { | 9906 | const dest_is_comptime_float = switch (dest_ty.zigTypeTag(mod)) { |
| 9929 | .ComptimeFloat => true, | 9907 | .ComptimeFloat => true, |
| 9930 | .Float => false, | 9908 | .Float => false, |
| ... | @@ -9932,7 +9910,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -9932,7 +9910,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9932 | block, | 9910 | block, |
| 9933 | dest_ty_src, | 9911 | dest_ty_src, |
| 9934 | "expected float type, found '{}'", | 9912 | "expected float type, found '{}'", |
| 9935 | .{dest_ty.fmt(sema.mod)}, | 9913 | .{dest_ty.fmt(mod)}, |
| 9936 | ), | 9914 | ), |
| 9937 | }; | 9915 | }; |
| 9938 | | 9916 | |
| ... | @@ -9943,7 +9921,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -9943,7 +9921,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9943 | block, | 9921 | block, |
| 9944 | operand_src, | 9922 | operand_src, |
| 9945 | "expected float type, found '{}'", | 9923 | "expected float type, found '{}'", |
| 9946 | .{operand_ty.fmt(sema.mod)}, | 9924 | .{operand_ty.fmt(mod)}, |
| 9947 | ), | 9925 | ), |
| 9948 | } | 9926 | } |
| 9949 | | 9927 | |
| ... | @@ -10002,7 +9980,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10002,7 +9980,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10002 | const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node }; | 9980 | const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node }; |
| 10003 | const msg = msg: { | 9981 | const msg = msg: { |
| 10004 | const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{ | 9982 | const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{ |
| 10005 | indexable_ty.fmt(sema.mod), | 9983 | indexable_ty.fmt(mod), |
| 10006 | }); | 9984 | }); |
| 10007 | errdefer msg.destroy(sema.gpa); | 9985 | errdefer msg.destroy(sema.gpa); |
| 10008 | if (indexable_ty.zigTypeTag(mod) == .Array) { | 9986 | if (indexable_ty.zigTypeTag(mod) == .Array) { |
| ... | @@ -10143,12 +10121,12 @@ fn zirSwitchCapture( | ... | @@ -10143,12 +10121,12 @@ fn zirSwitchCapture( |
| 10143 | const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable; | 10121 | const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable; |
| 10144 | const resolved_item_val = try sema.resolveLazyValue(item_val); | 10122 | const resolved_item_val = try sema.resolveLazyValue(item_val); |
| 10145 | if (operand_ty.zigTypeTag(mod) == .Union) { | 10123 | if (operand_ty.zigTypeTag(mod) == .Union) { |
| 10146 | const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(resolved_item_val, sema.mod).?); | 10124 | const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(resolved_item_val, mod).?); |
| 10147 | const union_obj = mod.typeToUnion(operand_ty).?; | 10125 | const union_obj = mod.typeToUnion(operand_ty).?; |
| 10148 | const field_ty = union_obj.fields.values()[field_index].ty; | 10126 | const field_ty = union_obj.fields.values()[field_index].ty; |
| 10149 | if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| { | 10127 | if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| { |
| 10150 | if (is_ref) { | 10128 | if (is_ref) { |
| 10151 | const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{ | 10129 | const ptr_field_ty = try Type.ptr(sema.arena, mod, .{ |
| 10152 | .pointee_type = field_ty, | 10130 | .pointee_type = field_ty, |
| 10153 | .mutable = operand_ptr_ty.ptrIsMutable(mod), | 10131 | .mutable = operand_ptr_ty.ptrIsMutable(mod), |
| 10154 | .@"volatile" = operand_ptr_ty.isVolatilePtr(mod), | 10132 | .@"volatile" = operand_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -10168,7 +10146,7 @@ fn zirSwitchCapture( | ... | @@ -10168,7 +10146,7 @@ fn zirSwitchCapture( |
| 10168 | ); | 10146 | ); |
| 10169 | } | 10147 | } |
| 10170 | if (is_ref) { | 10148 | if (is_ref) { |
| 10171 | const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{ | 10149 | const ptr_field_ty = try Type.ptr(sema.arena, mod, .{ |
| 10172 | .pointee_type = field_ty, | 10150 | .pointee_type = field_ty, |
| 10173 | .mutable = operand_ptr_ty.ptrIsMutable(mod), | 10151 | .mutable = operand_ptr_ty.ptrIsMutable(mod), |
| 10174 | .@"volatile" = operand_ptr_ty.isVolatilePtr(mod), | 10152 | .@"volatile" = operand_ptr_ty.isVolatilePtr(mod), |
| ... | @@ -10221,7 +10199,7 @@ fn zirSwitchCapture( | ... | @@ -10221,7 +10199,7 @@ fn zirSwitchCapture( |
| 10221 | // Previous switch validation ensured this will succeed | 10199 | // Previous switch validation ensured this will succeed |
| 10222 | const first_item_val = sema.resolveConstValue(block, .unneeded, first_item, "") catch unreachable; | 10200 | const first_item_val = sema.resolveConstValue(block, .unneeded, first_item, "") catch unreachable; |
| 10223 | | 10201 | |
| 10224 | const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, sema.mod).?); | 10202 | const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, mod).?); |
| 10225 | const first_field = union_obj.fields.values()[first_field_index]; | 10203 | const first_field = union_obj.fields.values()[first_field_index]; |
| 10226 | | 10204 | |
| 10227 | for (items[1..], 0..) |item, i| { | 10205 | for (items[1..], 0..) |item, i| { |
| ... | @@ -10229,22 +10207,22 @@ fn zirSwitchCapture( | ... | @@ -10229,22 +10207,22 @@ fn zirSwitchCapture( |
| 10229 | // Previous switch validation ensured this will succeed | 10207 | // Previous switch validation ensured this will succeed |
| 10230 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable; | 10208 | const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable; |
| 10231 | | 10209 | |
| 10232 | const field_index = operand_ty.unionTagFieldIndex(item_val, sema.mod).?; | 10210 | const field_index = operand_ty.unionTagFieldIndex(item_val, mod).?; |
| 10233 | const field = union_obj.fields.values()[field_index]; | 10211 | const field = union_obj.fields.values()[field_index]; |
| 10234 | if (!field.ty.eql(first_field.ty, sema.mod)) { | 10212 | if (!field.ty.eql(first_field.ty, mod)) { |
| 10235 | const msg = msg: { | 10213 | const msg = msg: { |
| 10236 | const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index }; | 10214 | const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index }; |
| 10237 | const capture_src = raw_capture_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10215 | const capture_src = raw_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10238 | | 10216 | |
| 10239 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); | 10217 | const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{}); |
| 10240 | errdefer msg.destroy(gpa); | 10218 | errdefer msg.destroy(gpa); |
| 10241 | | 10219 | |
| 10242 | const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } }; | 10220 | const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } }; |
| 10243 | const first_item_src = raw_first_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10221 | const first_item_src = raw_first_item_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10244 | const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } }; | 10222 | const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } }; |
| 10245 | const item_src = raw_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first); | 10223 | const item_src = raw_item_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first); |
| 10246 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)}); | 10224 | try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(mod)}); |
| 10247 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)}); | 10225 | try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(mod)}); |
| 10248 | break :msg msg; | 10226 | break :msg msg; |
| 10249 | }; | 10227 | }; |
| 10250 | return sema.failWithOwnedErrorMsg(msg); | 10228 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -10252,7 +10230,7 @@ fn zirSwitchCapture( | ... | @@ -10252,7 +10230,7 @@ fn zirSwitchCapture( |
| 10252 | } | 10230 | } |
| 10253 | | 10231 | |
| 10254 | if (is_ref) { | 10232 | if (is_ref) { |
| 10255 | const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{ | 10233 | const field_ty_ptr = try Type.ptr(sema.arena, mod, .{ |
| 10256 | .pointee_type = first_field.ty, | 10234 | .pointee_type = first_field.ty, |
| 10257 | .@"addrspace" = .generic, | 10235 | .@"addrspace" = .generic, |
| 10258 | .mutable = operand_ptr_ty.ptrIsMutable(mod), | 10236 | .mutable = operand_ptr_ty.ptrIsMutable(mod), |
| ... | @@ -10288,8 +10266,7 @@ fn zirSwitchCapture( | ... | @@ -10288,8 +10266,7 @@ fn zirSwitchCapture( |
| 10288 | const item_ref = try sema.resolveInst(item); | 10266 | const item_ref = try sema.resolveInst(item); |
| 10289 | // Previous switch validation ensured this will succeed | 10267 | // Previous switch validation ensured this will succeed |
| 10290 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable; | 10268 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable; |
| 10291 | const name_ip = try mod.intern_pool.getOrPutString(gpa, item_val.getError(mod).?); | 10269 | names.putAssumeCapacityNoClobber(item_val.getErrorName(mod).unwrap().?, {}); |
| 10292 | names.putAssumeCapacityNoClobber(name_ip, {}); | | |
| 10293 | } | 10270 | } |
| 10294 | const else_error_ty = try mod.errorSetFromUnsortedNames(names.keys()); | 10271 | const else_error_ty = try mod.errorSetFromUnsortedNames(names.keys()); |
| 10295 | | 10272 | |
| ... | @@ -10299,7 +10276,7 @@ fn zirSwitchCapture( | ... | @@ -10299,7 +10276,7 @@ fn zirSwitchCapture( |
| 10299 | // Previous switch validation ensured this will succeed | 10276 | // Previous switch validation ensured this will succeed |
| 10300 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable; | 10277 | const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable; |
| 10301 | | 10278 | |
| 10302 | const item_ty = try mod.singleErrorSetType(item_val.getError(mod).?); | 10279 | const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?); |
| 10303 | return sema.bitCast(block, item_ty, operand, operand_src, null); | 10280 | return sema.bitCast(block, item_ty, operand, operand_src, null); |
| 10304 | } | 10281 | } |
| 10305 | }, | 10282 | }, |
| ... | @@ -10331,7 +10308,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile | ... | @@ -10331,7 +10308,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 10331 | if (operand_ty.zigTypeTag(mod) != .Union) { | 10308 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 10332 | const msg = msg: { | 10309 | const msg = msg: { |
| 10333 | const msg = try sema.errMsg(block, src, "cannot capture tag of non-union type '{}'", .{ | 10310 | const msg = try sema.errMsg(block, src, "cannot capture tag of non-union type '{}'", .{ |
| 10334 | operand_ty.fmt(sema.mod), | 10311 | operand_ty.fmt(mod), |
| 10335 | }); | 10312 | }); |
| 10336 | errdefer msg.destroy(sema.gpa); | 10313 | errdefer msg.destroy(sema.gpa); |
| 10337 | try sema.addDeclaredHereNote(msg, operand_ty); | 10314 | try sema.addDeclaredHereNote(msg, operand_ty); |
| ... | @@ -10375,7 +10352,7 @@ fn zirSwitchCond( | ... | @@ -10375,7 +10352,7 @@ fn zirSwitchCond( |
| 10375 | .Enum, | 10352 | .Enum, |
| 10376 | => { | 10353 | => { |
| 10377 | if (operand_ty.isSlice(mod)) { | 10354 | if (operand_ty.isSlice(mod)) { |
| 10378 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}); | 10355 | return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)}); |
| 10379 | } | 10356 | } |
| 10380 | if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| { | 10357 | if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| { |
| 10381 | return sema.addConstant(operand_ty, opv); | 10358 | return sema.addConstant(operand_ty, opv); |
| ... | @@ -10389,8 +10366,8 @@ fn zirSwitchCond( | ... | @@ -10389,8 +10366,8 @@ fn zirSwitchCond( |
| 10389 | const msg = msg: { | 10366 | const msg = msg: { |
| 10390 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); | 10367 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); |
| 10391 | errdefer msg.destroy(sema.gpa); | 10368 | errdefer msg.destroy(sema.gpa); |
| 10392 | if (union_ty.declSrcLocOrNull(sema.mod)) |union_src| { | 10369 | if (union_ty.declSrcLocOrNull(mod)) |union_src| { |
| 10393 | try sema.mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); | 10370 | try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); |
| 10394 | } | 10371 | } |
| 10395 | break :msg msg; | 10372 | break :msg msg; |
| 10396 | }; | 10373 | }; |
| ... | @@ -10410,11 +10387,11 @@ fn zirSwitchCond( | ... | @@ -10410,11 +10387,11 @@ fn zirSwitchCond( |
| 10410 | .Vector, | 10387 | .Vector, |
| 10411 | .Frame, | 10388 | .Frame, |
| 10412 | .AnyFrame, | 10389 | .AnyFrame, |
| 10413 | => return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}), | 10390 | => return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)}), |
| 10414 | } | 10391 | } |
| 10415 | } | 10392 | } |
| 10416 | | 10393 | |
| 10417 | const SwitchErrorSet = std.StringHashMap(Module.SwitchProngSrc); | 10394 | const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc); |
| 10418 | | 10395 | |
| 10419 | fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10396 | fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 10420 | const tracy = trace(@src()); | 10397 | const tracy = trace(@src()); |
| ... | @@ -10593,8 +10570,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10593,8 +10570,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10593 | operand_ty, | 10570 | operand_ty, |
| 10594 | i, | 10571 | i, |
| 10595 | msg, | 10572 | msg, |
| 10596 | "unhandled enumeration value: '{s}'", | 10573 | "unhandled enumeration value: '{}'", |
| 10597 | .{ip.stringToSlice(field_name)}, | 10574 | .{field_name.fmt(&mod.intern_pool)}, |
| 10598 | ); | 10575 | ); |
| 10599 | } | 10576 | } |
| 10600 | try mod.errNoteNonLazy( | 10577 | try mod.errNoteNonLazy( |
| ... | @@ -10677,8 +10654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10677,8 +10654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10677 | var maybe_msg: ?*Module.ErrorMsg = null; | 10654 | var maybe_msg: ?*Module.ErrorMsg = null; |
| 10678 | errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa); | 10655 | errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa); |
| 10679 | | 10656 | |
| 10680 | for (operand_ty.errorSetNames(mod)) |error_name_ip| { | 10657 | for (operand_ty.errorSetNames(mod)) |error_name| { |
| 10681 | const error_name = ip.stringToSlice(error_name_ip); | | |
| 10682 | if (!seen_errors.contains(error_name) and special_prong != .@"else") { | 10658 | if (!seen_errors.contains(error_name) and special_prong != .@"else") { |
| 10683 | const msg = maybe_msg orelse blk: { | 10659 | const msg = maybe_msg orelse blk: { |
| 10684 | maybe_msg = try sema.errMsg( | 10660 | maybe_msg = try sema.errMsg( |
| ... | @@ -10694,8 +10670,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10694,8 +10670,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10694 | block, | 10670 | block, |
| 10695 | src, | 10671 | src, |
| 10696 | msg, | 10672 | msg, |
| 10697 | "unhandled error value: 'error.{s}'", | 10673 | "unhandled error value: 'error.{}'", |
| 10698 | .{error_name}, | 10674 | .{error_name.fmt(ip)}, |
| 10699 | ); | 10675 | ); |
| 10700 | } | 10676 | } |
| 10701 | } | 10677 | } |
| ... | @@ -10746,11 +10722,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10746,11 +10722,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10746 | const error_names = operand_ty.errorSetNames(mod); | 10722 | const error_names = operand_ty.errorSetNames(mod); |
| 10747 | var names: Module.Fn.InferredErrorSet.NameMap = .{}; | 10723 | var names: Module.Fn.InferredErrorSet.NameMap = .{}; |
| 10748 | try names.ensureUnusedCapacity(sema.arena, error_names.len); | 10724 | try names.ensureUnusedCapacity(sema.arena, error_names.len); |
| 10749 | for (error_names) |error_name_ip| { | 10725 | for (error_names) |error_name| { |
| 10750 | const error_name = ip.stringToSlice(error_name_ip); | | |
| 10751 | if (seen_errors.contains(error_name)) continue; | 10726 | if (seen_errors.contains(error_name)) continue; |
| 10752 | | 10727 | |
| 10753 | names.putAssumeCapacityNoClobber(error_name_ip, {}); | 10728 | names.putAssumeCapacityNoClobber(error_name, {}); |
| 10754 | } | 10729 | } |
| 10755 | // No need to keep the hash map metadata correct; here we | 10730 | // No need to keep the hash map metadata correct; here we |
| 10756 | // extract the (sorted) keys only. | 10731 | // extract the (sorted) keys only. |
| ... | @@ -11500,14 +11475,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -11500,14 +11475,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 11500 | }); | 11475 | }); |
| 11501 | } | 11476 | } |
| 11502 | for (0..operand_ty.errorSetNames(mod).len) |i| { | 11477 | for (0..operand_ty.errorSetNames(mod).len) |i| { |
| 11503 | const error_name_ip = operand_ty.errorSetNames(mod)[i]; | 11478 | const error_name = operand_ty.errorSetNames(mod)[i]; |
| 11504 | const error_name = mod.intern_pool.stringToSlice(error_name_ip); | | |
| 11505 | if (seen_errors.contains(error_name)) continue; | 11479 | if (seen_errors.contains(error_name)) continue; |
| 11506 | cases_len += 1; | 11480 | cases_len += 1; |
| 11507 | | 11481 | |
| 11508 | const item_val = try mod.intern(.{ .err = .{ | 11482 | const item_val = try mod.intern(.{ .err = .{ |
| 11509 | .ty = operand_ty.toIntern(), | 11483 | .ty = operand_ty.toIntern(), |
| 11510 | .name = error_name_ip, | 11484 | .name = error_name, |
| 11511 | } }); | 11485 | } }); |
| 11512 | const item_ref = try sema.addConstant(operand_ty, item_val.toValue()); | 11486 | const item_ref = try sema.addConstant(operand_ty, item_val.toValue()); |
| 11513 | case_block.inline_case_capture = item_ref; | 11487 | case_block.inline_case_capture = item_ref; |
| ... | @@ -11754,7 +11728,7 @@ fn resolveSwitchItemVal( | ... | @@ -11754,7 +11728,7 @@ fn resolveSwitchItemVal( |
| 11754 | return val.toIntern(); | 11728 | return val.toIntern(); |
| 11755 | } else |err| switch (err) { | 11729 | } else |err| switch (err) { |
| 11756 | error.NeededSourceLocation => { | 11730 | error.NeededSourceLocation => { |
| 11757 | const src = switch_prong_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 11731 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 11758 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | 11732 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); |
| 11759 | unreachable; | 11733 | unreachable; |
| 11760 | }, | 11734 | }, |
| ... | @@ -11827,7 +11801,7 @@ fn validateSwitchItemError( | ... | @@ -11827,7 +11801,7 @@ fn validateSwitchItemError( |
| 11827 | const ip = &sema.mod.intern_pool; | 11801 | const ip = &sema.mod.intern_pool; |
| 11828 | const item = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); | 11802 | const item = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none); |
| 11829 | // TODO: Do i need to typecheck here? | 11803 | // TODO: Do i need to typecheck here? |
| 11830 | const error_name = ip.stringToSlice(ip.indexToKey(item).err.name); | 11804 | const error_name = ip.indexToKey(item).err.name; |
| 11831 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev| | 11805 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev| |
| 11832 | prev.value | 11806 | prev.value |
| 11833 | else | 11807 | else |
| ... | @@ -11844,7 +11818,7 @@ fn validateSwitchDupe( | ... | @@ -11844,7 +11818,7 @@ fn validateSwitchDupe( |
| 11844 | ) CompileError!void { | 11818 | ) CompileError!void { |
| 11845 | const prev_prong_src = maybe_prev_src orelse return; | 11819 | const prev_prong_src = maybe_prev_src orelse return; |
| 11846 | const mod = sema.mod; | 11820 | const mod = sema.mod; |
| 11847 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 11821 | const block_src_decl = mod.declPtr(block.src_decl); |
| 11848 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | 11822 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11849 | const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | 11823 | const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11850 | const msg = msg: { | 11824 | const msg = msg: { |
| ... | @@ -11884,7 +11858,7 @@ fn validateSwitchItemBool( | ... | @@ -11884,7 +11858,7 @@ fn validateSwitchItemBool( |
| 11884 | false_count.* += 1; | 11858 | false_count.* += 1; |
| 11885 | } | 11859 | } |
| 11886 | if (true_count.* + false_count.* > 2) { | 11860 | if (true_count.* + false_count.* > 2) { |
| 11887 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 11861 | const block_src_decl = mod.declPtr(block.src_decl); |
| 11888 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | 11862 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 11889 | return sema.fail(block, src, "duplicate switch value", .{}); | 11863 | return sema.fail(block, src, "duplicate switch value", .{}); |
| 11890 | } | 11864 | } |
| ... | @@ -12020,7 +11994,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind | ... | @@ -12020,7 +11994,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind |
| 12020 | } | 11994 | } |
| 12021 | if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| { | 11995 | if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| { |
| 12022 | if (!operand_ty.isError(mod)) return; | 11996 | if (!operand_ty.isError(mod)) return; |
| 12023 | if (val.getError(mod) == null) return; | 11997 | if (val.getErrorName(mod) == .none) return; |
| 12024 | try sema.maybeErrorUnwrapComptime(block, body, err_operand); | 11998 | try sema.maybeErrorUnwrapComptime(block, body, err_operand); |
| 12025 | } | 11999 | } |
| 12026 | } | 12000 | } |
| ... | @@ -12042,8 +12016,8 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I | ... | @@ -12042,8 +12016,8 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 12042 | const src = inst_data.src(); | 12016 | const src = inst_data.src(); |
| 12043 | | 12017 | |
| 12044 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 12018 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 12045 | if (val.getError(sema.mod)) |name| { | 12019 | if (val.getErrorName(sema.mod).unwrap()) |name| { |
| 12046 | return sema.fail(block, src, "caught unexpected error '{s}'", .{name}); | 12020 | return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&sema.mod.intern_pool)}); |
| 12047 | } | 12021 | } |
| 12048 | } | 12022 | } |
| 12049 | } | 12023 | } |
| ... | @@ -12073,7 +12047,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12073,7 +12047,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12073 | if (anon_struct.names.len != 0) { | 12047 | if (anon_struct.names.len != 0) { |
| 12074 | break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null; | 12048 | break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null; |
| 12075 | } else { | 12049 | } else { |
| 12076 | const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch break :hf false; | 12050 | const field_index = field_name.toUnsigned(ip) orelse break :hf false; |
| 12077 | break :hf field_index < ty.structFieldCount(mod); | 12051 | break :hf field_index < ty.structFieldCount(mod); |
| 12078 | } | 12052 | } |
| 12079 | }, | 12053 | }, |
| ... | @@ -12094,7 +12068,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -12094,7 +12068,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 12094 | else => {}, | 12068 | else => {}, |
| 12095 | } | 12069 | } |
| 12096 | return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{ | 12070 | return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{ |
| 12097 | ty.fmt(sema.mod), | 12071 | ty.fmt(mod), |
| 12098 | }); | 12072 | }); |
| 12099 | }; | 12073 | }; |
| 12100 | if (has_field) { | 12074 | if (has_field) { |
| ... | @@ -12209,7 +12183,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R | ... | @@ -12209,7 +12183,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R |
| 12209 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | 12183 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; |
| 12210 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); | 12184 | const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code)); |
| 12211 | _ = try mod.getErrorValue(name); | 12185 | _ = try mod.getErrorValue(name); |
| 12212 | const error_set_type = try mod.singleErrorSetTypeNts(name); | 12186 | const error_set_type = try mod.singleErrorSetType(name); |
| 12213 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 12187 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 12214 | .ty = error_set_type.toIntern(), | 12188 | .ty = error_set_type.toIntern(), |
| 12215 | .name = name, | 12189 | .name = name, |
| ... | @@ -12260,36 +12234,36 @@ fn zirShl( | ... | @@ -12260,36 +12234,36 @@ fn zirShl( |
| 12260 | if (rhs_ty.zigTypeTag(mod) == .Vector) { | 12234 | if (rhs_ty.zigTypeTag(mod) == .Vector) { |
| 12261 | var i: usize = 0; | 12235 | var i: usize = 0; |
| 12262 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { | 12236 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { |
| 12263 | const rhs_elem = try rhs_val.elemValue(sema.mod, i); | 12237 | const rhs_elem = try rhs_val.elemValue(mod, i); |
| 12264 | if (rhs_elem.compareHetero(.gte, bit_value, mod)) { | 12238 | if (rhs_elem.compareHetero(.gte, bit_value, mod)) { |
| 12265 | return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{ | 12239 | return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{ |
| 12266 | rhs_elem.fmtValue(scalar_ty, sema.mod), | 12240 | rhs_elem.fmtValue(scalar_ty, mod), |
| 12267 | i, | 12241 | i, |
| 12268 | scalar_ty.fmt(sema.mod), | 12242 | scalar_ty.fmt(mod), |
| 12269 | }); | 12243 | }); |
| 12270 | } | 12244 | } |
| 12271 | } | 12245 | } |
| 12272 | } else if (rhs_val.compareHetero(.gte, bit_value, mod)) { | 12246 | } else if (rhs_val.compareHetero(.gte, bit_value, mod)) { |
| 12273 | return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{ | 12247 | return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{ |
| 12274 | rhs_val.fmtValue(scalar_ty, sema.mod), | 12248 | rhs_val.fmtValue(scalar_ty, mod), |
| 12275 | scalar_ty.fmt(sema.mod), | 12249 | scalar_ty.fmt(mod), |
| 12276 | }); | 12250 | }); |
| 12277 | } | 12251 | } |
| 12278 | } | 12252 | } |
| 12279 | if (rhs_ty.zigTypeTag(mod) == .Vector) { | 12253 | if (rhs_ty.zigTypeTag(mod) == .Vector) { |
| 12280 | var i: usize = 0; | 12254 | var i: usize = 0; |
| 12281 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { | 12255 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { |
| 12282 | const rhs_elem = try rhs_val.elemValue(sema.mod, i); | 12256 | const rhs_elem = try rhs_val.elemValue(mod, i); |
| 12283 | if (rhs_elem.compareHetero(.lt, try mod.intValue(scalar_rhs_ty, 0), mod)) { | 12257 | if (rhs_elem.compareHetero(.lt, try mod.intValue(scalar_rhs_ty, 0), mod)) { |
| 12284 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | 12258 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ |
| 12285 | rhs_elem.fmtValue(scalar_ty, sema.mod), | 12259 | rhs_elem.fmtValue(scalar_ty, mod), |
| 12286 | i, | 12260 | i, |
| 12287 | }); | 12261 | }); |
| 12288 | } | 12262 | } |
| 12289 | } | 12263 | } |
| 12290 | } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) { | 12264 | } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) { |
| 12291 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | 12265 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ |
| 12292 | rhs_val.fmtValue(scalar_ty, sema.mod), | 12266 | rhs_val.fmtValue(scalar_ty, mod), |
| 12293 | }); | 12267 | }); |
| 12294 | } | 12268 | } |
| 12295 | } | 12269 | } |
| ... | @@ -12305,25 +12279,25 @@ fn zirShl( | ... | @@ -12305,25 +12279,25 @@ fn zirShl( |
| 12305 | | 12279 | |
| 12306 | const val = switch (air_tag) { | 12280 | const val = switch (air_tag) { |
| 12307 | .shl_exact => val: { | 12281 | .shl_exact => val: { |
| 12308 | const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, sema.mod); | 12282 | const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, mod); |
| 12309 | if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) { | 12283 | if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) { |
| 12310 | break :val shifted.wrapped_result; | 12284 | break :val shifted.wrapped_result; |
| 12311 | } | 12285 | } |
| 12312 | if (shifted.overflow_bit.compareAllWithZero(.eq, sema.mod)) { | 12286 | if (shifted.overflow_bit.compareAllWithZero(.eq, mod)) { |
| 12313 | break :val shifted.wrapped_result; | 12287 | break :val shifted.wrapped_result; |
| 12314 | } | 12288 | } |
| 12315 | return sema.fail(block, src, "operation caused overflow", .{}); | 12289 | return sema.fail(block, src, "operation caused overflow", .{}); |
| 12316 | }, | 12290 | }, |
| 12317 | | 12291 | |
| 12318 | .shl_sat => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) | 12292 | .shl_sat => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) |
| 12319 | try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod) | 12293 | try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod) |
| 12320 | else | 12294 | else |
| 12321 | try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, sema.mod), | 12295 | try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, mod), |
| 12322 | | 12296 | |
| 12323 | .shl => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) | 12297 | .shl => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) |
| 12324 | try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod) | 12298 | try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod) |
| 12325 | else | 12299 | else |
| 12326 | try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, sema.mod), | 12300 | try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, mod), |
| 12327 | | 12301 | |
| 12328 | else => unreachable, | 12302 | else => unreachable, |
| 12329 | }; | 12303 | }; |
| ... | @@ -12441,36 +12415,36 @@ fn zirShr( | ... | @@ -12441,36 +12415,36 @@ fn zirShr( |
| 12441 | if (rhs_ty.zigTypeTag(mod) == .Vector) { | 12415 | if (rhs_ty.zigTypeTag(mod) == .Vector) { |
| 12442 | var i: usize = 0; | 12416 | var i: usize = 0; |
| 12443 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { | 12417 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { |
| 12444 | const rhs_elem = try rhs_val.elemValue(sema.mod, i); | 12418 | const rhs_elem = try rhs_val.elemValue(mod, i); |
| 12445 | if (rhs_elem.compareHetero(.gte, bit_value, mod)) { | 12419 | if (rhs_elem.compareHetero(.gte, bit_value, mod)) { |
| 12446 | return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{ | 12420 | return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{ |
| 12447 | rhs_elem.fmtValue(scalar_ty, sema.mod), | 12421 | rhs_elem.fmtValue(scalar_ty, mod), |
| 12448 | i, | 12422 | i, |
| 12449 | scalar_ty.fmt(sema.mod), | 12423 | scalar_ty.fmt(mod), |
| 12450 | }); | 12424 | }); |
| 12451 | } | 12425 | } |
| 12452 | } | 12426 | } |
| 12453 | } else if (rhs_val.compareHetero(.gte, bit_value, mod)) { | 12427 | } else if (rhs_val.compareHetero(.gte, bit_value, mod)) { |
| 12454 | return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{ | 12428 | return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{ |
| 12455 | rhs_val.fmtValue(scalar_ty, sema.mod), | 12429 | rhs_val.fmtValue(scalar_ty, mod), |
| 12456 | scalar_ty.fmt(sema.mod), | 12430 | scalar_ty.fmt(mod), |
| 12457 | }); | 12431 | }); |
| 12458 | } | 12432 | } |
| 12459 | } | 12433 | } |
| 12460 | if (rhs_ty.zigTypeTag(mod) == .Vector) { | 12434 | if (rhs_ty.zigTypeTag(mod) == .Vector) { |
| 12461 | var i: usize = 0; | 12435 | var i: usize = 0; |
| 12462 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { | 12436 | while (i < rhs_ty.vectorLen(mod)) : (i += 1) { |
| 12463 | const rhs_elem = try rhs_val.elemValue(sema.mod, i); | 12437 | const rhs_elem = try rhs_val.elemValue(mod, i); |
| 12464 | if (rhs_elem.compareHetero(.lt, try mod.intValue(rhs_ty.childType(mod), 0), mod)) { | 12438 | if (rhs_elem.compareHetero(.lt, try mod.intValue(rhs_ty.childType(mod), 0), mod)) { |
| 12465 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | 12439 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ |
| 12466 | rhs_elem.fmtValue(scalar_ty, sema.mod), | 12440 | rhs_elem.fmtValue(scalar_ty, mod), |
| 12467 | i, | 12441 | i, |
| 12468 | }); | 12442 | }); |
| 12469 | } | 12443 | } |
| 12470 | } | 12444 | } |
| 12471 | } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) { | 12445 | } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) { |
| 12472 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | 12446 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ |
| 12473 | rhs_val.fmtValue(scalar_ty, sema.mod), | 12447 | rhs_val.fmtValue(scalar_ty, mod), |
| 12474 | }); | 12448 | }); |
| 12475 | } | 12449 | } |
| 12476 | if (maybe_lhs_val) |lhs_val| { | 12450 | if (maybe_lhs_val) |lhs_val| { |
| ... | @@ -12479,12 +12453,12 @@ fn zirShr( | ... | @@ -12479,12 +12453,12 @@ fn zirShr( |
| 12479 | } | 12453 | } |
| 12480 | if (air_tag == .shr_exact) { | 12454 | if (air_tag == .shr_exact) { |
| 12481 | // Detect if any ones would be shifted out. | 12455 | // Detect if any ones would be shifted out. |
| 12482 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, sema.mod); | 12456 | const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, mod); |
| 12483 | if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) { | 12457 | if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) { |
| 12484 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); | 12458 | return sema.fail(block, src, "exact shift shifted out 1 bits", .{}); |
| 12485 | } | 12459 | } |
| 12486 | } | 12460 | } |
| 12487 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, sema.mod); | 12461 | const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, mod); |
| 12488 | return sema.addConstant(lhs_ty, val); | 12462 | return sema.addConstant(lhs_ty, val); |
| 12489 | } else { | 12463 | } else { |
| 12490 | break :rs lhs_src; | 12464 | break :rs lhs_src; |
| ... | @@ -12580,9 +12554,9 @@ fn zirBitwise( | ... | @@ -12580,9 +12554,9 @@ fn zirBitwise( |
| 12580 | if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| { | 12554 | if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| { |
| 12581 | if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| { | 12555 | if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| { |
| 12582 | const result_val = switch (air_tag) { | 12556 | const result_val = switch (air_tag) { |
| 12583 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod), | 12557 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod), |
| 12584 | .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod), | 12558 | .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod), |
| 12585 | .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod), | 12559 | .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, mod), |
| 12586 | else => unreachable, | 12560 | else => unreachable, |
| 12587 | }; | 12561 | }; |
| 12588 | return sema.addConstant(resolved_type, result_val); | 12562 | return sema.addConstant(resolved_type, result_val); |
| ... | @@ -12613,7 +12587,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12613,7 +12587,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12613 | | 12587 | |
| 12614 | if (scalar_type.zigTypeTag(mod) != .Int) { | 12588 | if (scalar_type.zigTypeTag(mod) != .Int) { |
| 12615 | return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{ | 12589 | return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{ |
| 12616 | operand_type.fmt(sema.mod), | 12590 | operand_type.fmt(mod), |
| 12617 | }); | 12591 | }); |
| 12618 | } | 12592 | } |
| 12619 | | 12593 | |
| ... | @@ -12624,15 +12598,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -12624,15 +12598,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12624 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod)); | 12598 | const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod)); |
| 12625 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); | 12599 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| 12626 | for (elems, 0..) |*elem, i| { | 12600 | for (elems, 0..) |*elem, i| { |
| 12627 | const elem_val = try val.elemValue(sema.mod, i); | 12601 | const elem_val = try val.elemValue(mod, i); |
| 12628 | elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod)).intern(scalar_type, mod); | 12602 | elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, mod)).intern(scalar_type, mod); |
| 12629 | } | 12603 | } |
| 12630 | return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{ | 12604 | return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{ |
| 12631 | .ty = operand_type.toIntern(), | 12605 | .ty = operand_type.toIntern(), |
| 12632 | .storage = .{ .elems = elems }, | 12606 | .storage = .{ .elems = elems }, |
| 12633 | } })).toValue()); | 12607 | } })).toValue()); |
| 12634 | } else { | 12608 | } else { |
| 12635 | const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod); | 12609 | const result_val = try val.bitwiseNot(operand_type, sema.arena, mod); |
| 12636 | return sema.addConstant(operand_type, result_val); | 12610 | return sema.addConstant(operand_type, result_val); |
| 12637 | } | 12611 | } |
| 12638 | } | 12612 | } |
| ... | @@ -12949,7 +12923,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins | ... | @@ -12949,7 +12923,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 12949 | return Type.ArrayInfo{ | 12923 | return Type.ArrayInfo{ |
| 12950 | .elem_type = ptr_info.pointee_type, | 12924 | .elem_type = ptr_info.pointee_type, |
| 12951 | .sentinel = ptr_info.sentinel, | 12925 | .sentinel = ptr_info.sentinel, |
| 12952 | .len = val.sliceLen(sema.mod), | 12926 | .len = val.sliceLen(mod), |
| 12953 | }; | 12927 | }; |
| 12954 | }, | 12928 | }, |
| 12955 | .One => { | 12929 | .One => { |
| ... | @@ -13195,14 +13169,14 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13195,14 +13169,14 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13195 | .Int, .ComptimeInt, .Float, .ComptimeFloat => false, | 13169 | .Int, .ComptimeInt, .Float, .ComptimeFloat => false, |
| 13196 | else => true, | 13170 | else => true, |
| 13197 | }) { | 13171 | }) { |
| 13198 | return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)}); | 13172 | return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)}); |
| 13199 | } | 13173 | } |
| 13200 | | 13174 | |
| 13201 | if (rhs_scalar_ty.isAnyFloat()) { | 13175 | if (rhs_scalar_ty.isAnyFloat()) { |
| 13202 | // We handle float negation here to ensure negative zero is represented in the bits. | 13176 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 13203 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { | 13177 | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 13204 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty); | 13178 | if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty); |
| 13205 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod)); | 13179 | return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, mod)); |
| 13206 | } | 13180 | } |
| 13207 | try sema.requireRuntimeBlock(block, src, null); | 13181 | try sema.requireRuntimeBlock(block, src, null); |
| 13208 | return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs); | 13182 | return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs); |
| ... | @@ -13225,7 +13199,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -13225,7 +13199,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 13225 | | 13199 | |
| 13226 | switch (rhs_scalar_ty.zigTypeTag(mod)) { | 13200 | switch (rhs_scalar_ty.zigTypeTag(mod)) { |
| 13227 | .Int, .ComptimeInt, .Float, .ComptimeFloat => {}, | 13201 | .Int, .ComptimeInt, .Float, .ComptimeFloat => {}, |
| 13228 | else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)}), | 13202 | else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)}), |
| 13229 | } | 13203 | } |
| 13230 | | 13204 | |
| 13231 | const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); | 13205 | const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))); |
| ... | @@ -14099,8 +14073,8 @@ fn intRem( | ... | @@ -14099,8 +14073,8 @@ fn intRem( |
| 14099 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); | 14073 | const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod)); |
| 14100 | const scalar_ty = ty.scalarType(mod); | 14074 | const scalar_ty = ty.scalarType(mod); |
| 14101 | for (result_data, 0..) |*scalar, i| { | 14075 | for (result_data, 0..) |*scalar, i| { |
| 14102 | const lhs_elem = try lhs.elemValue(sema.mod, i); | 14076 | const lhs_elem = try lhs.elemValue(mod, i); |
| 14103 | const rhs_elem = try rhs.elemValue(sema.mod, i); | 14077 | const rhs_elem = try rhs.elemValue(mod, i); |
| 14104 | scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod); | 14078 | scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod); |
| 14105 | } | 14079 | } |
| 14106 | return (try mod.intern(.{ .aggregate = .{ | 14080 | return (try mod.intern(.{ .aggregate = .{ |
| ... | @@ -14499,7 +14473,7 @@ fn zirOverflowArithmetic( | ... | @@ -14499,7 +14473,7 @@ fn zirOverflowArithmetic( |
| 14499 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; | 14473 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 14500 | } | 14474 | } |
| 14501 | | 14475 | |
| 14502 | const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod); | 14476 | const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, mod); |
| 14503 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; | 14477 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; |
| 14504 | } | 14478 | } |
| 14505 | } | 14479 | } |
| ... | @@ -14917,7 +14891,7 @@ fn analyzeArithmetic( | ... | @@ -14917,7 +14891,7 @@ fn analyzeArithmetic( |
| 14917 | } | 14891 | } |
| 14918 | if (is_int) { | 14892 | if (is_int) { |
| 14919 | var overflow_idx: ?usize = null; | 14893 | var overflow_idx: ?usize = null; |
| 14920 | const product = try lhs_val.intMul(rhs_val, resolved_type, &overflow_idx, sema.arena, sema.mod); | 14894 | const product = try lhs_val.intMul(rhs_val, resolved_type, &overflow_idx, sema.arena, mod); |
| 14921 | if (overflow_idx) |vec_idx| { | 14895 | if (overflow_idx) |vec_idx| { |
| 14922 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx); | 14896 | return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx); |
| 14923 | } | 14897 | } |
| ... | @@ -14925,7 +14899,7 @@ fn analyzeArithmetic( | ... | @@ -14925,7 +14899,7 @@ fn analyzeArithmetic( |
| 14925 | } else { | 14899 | } else { |
| 14926 | return sema.addConstant( | 14900 | return sema.addConstant( |
| 14927 | resolved_type, | 14901 | resolved_type, |
| 14928 | try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, sema.mod), | 14902 | try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, mod), |
| 14929 | ); | 14903 | ); |
| 14930 | } | 14904 | } |
| 14931 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 14905 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| ... | @@ -14975,7 +14949,7 @@ fn analyzeArithmetic( | ... | @@ -14975,7 +14949,7 @@ fn analyzeArithmetic( |
| 14975 | } | 14949 | } |
| 14976 | return sema.addConstant( | 14950 | return sema.addConstant( |
| 14977 | resolved_type, | 14951 | resolved_type, |
| 14978 | try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, sema.mod), | 14952 | try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, mod), |
| 14979 | ); | 14953 | ); |
| 14980 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; | 14954 | } else break :rs .{ .src = lhs_src, .air_tag = air_tag }; |
| 14981 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; | 14955 | } else break :rs .{ .src = rhs_src, .air_tag = air_tag }; |
| ... | @@ -15023,9 +14997,9 @@ fn analyzeArithmetic( | ... | @@ -15023,9 +14997,9 @@ fn analyzeArithmetic( |
| 15023 | } | 14997 | } |
| 15024 | | 14998 | |
| 15025 | const val = if (scalar_tag == .ComptimeInt) | 14999 | const val = if (scalar_tag == .ComptimeInt) |
| 15026 | try lhs_val.intMul(rhs_val, resolved_type, undefined, sema.arena, sema.mod) | 15000 | try lhs_val.intMul(rhs_val, resolved_type, undefined, sema.arena, mod) |
| 15027 | else | 15001 | else |
| 15028 | try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, sema.mod); | 15002 | try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, mod); |
| 15029 | | 15003 | |
| 15030 | return sema.addConstant(resolved_type, val); | 15004 | return sema.addConstant(resolved_type, val); |
| 15031 | } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat }; | 15005 | } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat }; |
| ... | @@ -15118,7 +15092,7 @@ fn analyzePtrArithmetic( | ... | @@ -15118,7 +15092,7 @@ fn analyzePtrArithmetic( |
| 15118 | // non zero). | 15092 | // non zero). |
| 15119 | const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align")); | 15093 | const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align")); |
| 15120 | | 15094 | |
| 15121 | break :t try Type.ptr(sema.arena, sema.mod, .{ | 15095 | break :t try Type.ptr(sema.arena, mod, .{ |
| 15122 | .pointee_type = ptr_info.pointee_type, | 15096 | .pointee_type = ptr_info.pointee_type, |
| 15123 | .sentinel = ptr_info.sentinel, | 15097 | .sentinel = ptr_info.sentinel, |
| 15124 | .@"align" = new_align, | 15098 | .@"align" = new_align, |
| ... | @@ -15150,7 +15124,7 @@ fn analyzePtrArithmetic( | ... | @@ -15150,7 +15124,7 @@ fn analyzePtrArithmetic( |
| 15150 | if (air_tag == .ptr_sub) { | 15124 | if (air_tag == .ptr_sub) { |
| 15151 | return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{}); | 15125 | return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{}); |
| 15152 | } | 15126 | } |
| 15153 | const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, sema.mod); | 15127 | const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, mod); |
| 15154 | return sema.addConstant(new_ptr_ty, new_ptr_val); | 15128 | return sema.addConstant(new_ptr_ty, new_ptr_val); |
| 15155 | } else break :rs offset_src; | 15129 | } else break :rs offset_src; |
| 15156 | } else break :rs ptr_src; | 15130 | } else break :rs ptr_src; |
| ... | @@ -15382,7 +15356,7 @@ fn zirCmpEq( | ... | @@ -15382,7 +15356,7 @@ fn zirCmpEq( |
| 15382 | | 15356 | |
| 15383 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { | 15357 | if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) { |
| 15384 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; | 15358 | const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty; |
| 15385 | return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type.fmt(sema.mod)}); | 15359 | return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type.fmt(mod)}); |
| 15386 | } | 15360 | } |
| 15387 | | 15361 | |
| 15388 | if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) { | 15362 | if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) { |
| ... | @@ -15419,7 +15393,7 @@ fn zirCmpEq( | ... | @@ -15419,7 +15393,7 @@ fn zirCmpEq( |
| 15419 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { | 15393 | if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) { |
| 15420 | const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs); | 15394 | const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs); |
| 15421 | const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs); | 15395 | const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs); |
| 15422 | if (lhs_as_type.eql(rhs_as_type, sema.mod) == (op == .eq)) { | 15396 | if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) { |
| 15423 | return Air.Inst.Ref.bool_true; | 15397 | return Air.Inst.Ref.bool_true; |
| 15424 | } else { | 15398 | } else { |
| 15425 | return Air.Inst.Ref.bool_false; | 15399 | return Air.Inst.Ref.bool_false; |
| ... | @@ -15444,7 +15418,7 @@ fn analyzeCmpUnionTag( | ... | @@ -15444,7 +15418,7 @@ fn analyzeCmpUnionTag( |
| 15444 | const msg = msg: { | 15418 | const msg = msg: { |
| 15445 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); | 15419 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 15446 | errdefer msg.destroy(sema.gpa); | 15420 | errdefer msg.destroy(sema.gpa); |
| 15447 | try sema.mod.errNoteNonLazy(union_ty.declSrcLoc(sema.mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(sema.mod)}); | 15421 | try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); |
| 15448 | break :msg msg; | 15422 | break :msg msg; |
| 15449 | }; | 15423 | }; |
| 15450 | return sema.failWithOwnedErrorMsg(msg); | 15424 | return sema.failWithOwnedErrorMsg(msg); |
| ... | @@ -15456,7 +15430,7 @@ fn analyzeCmpUnionTag( | ... | @@ -15456,7 +15430,7 @@ fn analyzeCmpUnionTag( |
| 15456 | | 15430 | |
| 15457 | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { | 15431 | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { |
| 15458 | if (enum_val.isUndef(mod)) return sema.addConstUndef(Type.bool); | 15432 | if (enum_val.isUndef(mod)) return sema.addConstUndef(Type.bool); |
| 15459 | const field_ty = union_ty.unionFieldType(enum_val, sema.mod); | 15433 | const field_ty = union_ty.unionFieldType(enum_val, mod); |
| 15460 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 15434 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 15461 | return Air.Inst.Ref.bool_false; | 15435 | return Air.Inst.Ref.bool_false; |
| 15462 | } | 15436 | } |
| ... | @@ -15524,7 +15498,7 @@ fn analyzeCmp( | ... | @@ -15524,7 +15498,7 @@ fn analyzeCmp( |
| 15524 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } }); | 15498 | const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } }); |
| 15525 | if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) { | 15499 | if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) { |
| 15526 | return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{ | 15500 | return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{ |
| 15527 | compareOperatorName(op), resolved_type.fmt(sema.mod), | 15501 | compareOperatorName(op), resolved_type.fmt(mod), |
| 15528 | }); | 15502 | }); |
| 15529 | } | 15503 | } |
| 15530 | const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src); | 15504 | const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src); |
| ... | @@ -15634,7 +15608,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -15634,7 +15608,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 15634 | .Undefined, | 15608 | .Undefined, |
| 15635 | .Null, | 15609 | .Null, |
| 15636 | .Opaque, | 15610 | .Opaque, |
| 15637 | => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(sema.mod)}), | 15611 | => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(mod)}), |
| 15638 | | 15612 | |
| 15639 | .Type, | 15613 | .Type, |
| 15640 | .EnumLiteral, | 15614 | .EnumLiteral, |
| ... | @@ -15677,7 +15651,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -15677,7 +15651,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 15677 | .Undefined, | 15651 | .Undefined, |
| 15678 | .Null, | 15652 | .Null, |
| 15679 | .Opaque, | 15653 | .Opaque, |
| 15680 | => return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(sema.mod)}), | 15654 | => return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(mod)}), |
| 15681 | | 15655 | |
| 15682 | .Type, | 15656 | .Type, |
| 15683 | .EnumLiteral, | 15657 | .EnumLiteral, |
| ... | @@ -17163,7 +17137,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi | ... | @@ -17163,7 +17137,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi |
| 17163 | block, | 17137 | block, |
| 17164 | src, | 17138 | src, |
| 17165 | "bit shifting operation expected integer type, found '{}'", | 17139 | "bit shifting operation expected integer type, found '{}'", |
| 17166 | .{operand.fmt(sema.mod)}, | 17140 | .{operand.fmt(mod)}, |
| 17167 | ); | 17141 | ); |
| 17168 | } | 17142 | } |
| 17169 | | 17143 | |
| ... | @@ -17395,7 +17369,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { | ... | @@ -17395,7 +17369,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 17395 | switch (ty.zigTypeTag(mod)) { | 17369 | switch (ty.zigTypeTag(mod)) { |
| 17396 | .ErrorSet, .ErrorUnion, .Undefined => return, | 17370 | .ErrorSet, .ErrorUnion, .Undefined => return, |
| 17397 | else => return sema.fail(block, src, "expected error union type, found '{}'", .{ | 17371 | else => return sema.fail(block, src, "expected error union type, found '{}'", .{ |
| 17398 | ty.fmt(sema.mod), | 17372 | ty.fmt(mod), |
| 17399 | }), | 17373 | }), |
| 17400 | } | 17374 | } |
| 17401 | } | 17375 | } |
| ... | @@ -17521,7 +17495,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -17521,7 +17495,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 17521 | const mod = sema.mod; | 17495 | const mod = sema.mod; |
| 17522 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { | 17496 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| 17523 | return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{ | 17497 | return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{ |
| 17524 | err_union_ty.fmt(sema.mod), | 17498 | err_union_ty.fmt(mod), |
| 17525 | }); | 17499 | }); |
| 17526 | } | 17500 | } |
| 17527 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union); | 17501 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union); |
| ... | @@ -17568,7 +17542,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -17568,7 +17542,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17568 | const mod = sema.mod; | 17542 | const mod = sema.mod; |
| 17569 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { | 17543 | if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) { |
| 17570 | return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{ | 17544 | return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{ |
| 17571 | err_union_ty.fmt(sema.mod), | 17545 | err_union_ty.fmt(mod), |
| 17572 | }); | 17546 | }); |
| 17573 | } | 17547 | } |
| 17574 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union); | 17548 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union); |
| ... | @@ -17590,7 +17564,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -17590,7 +17564,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17590 | | 17564 | |
| 17591 | const operand_ty = sema.typeOf(operand); | 17565 | const operand_ty = sema.typeOf(operand); |
| 17592 | const ptr_info = operand_ty.ptrInfo(mod); | 17566 | const ptr_info = operand_ty.ptrInfo(mod); |
| 17593 | const res_ty = try Type.ptr(sema.arena, sema.mod, .{ | 17567 | const res_ty = try Type.ptr(sema.arena, mod, .{ |
| 17594 | .pointee_type = err_union_ty.errorUnionPayload(mod), | 17568 | .pointee_type = err_union_ty.errorUnionPayload(mod), |
| 17595 | .@"addrspace" = ptr_info.@"addrspace", | 17569 | .@"addrspace" = ptr_info.@"addrspace", |
| 17596 | .mutable = ptr_info.mutable, | 17570 | .mutable = ptr_info.mutable, |
| ... | @@ -17693,7 +17667,7 @@ fn zirRetErrValue( | ... | @@ -17693,7 +17667,7 @@ fn zirRetErrValue( |
| 17693 | _ = try mod.getErrorValue(err_name); | 17667 | _ = try mod.getErrorValue(err_name); |
| 17694 | const src = inst_data.src(); | 17668 | const src = inst_data.src(); |
| 17695 | // Return the error code from the function. | 17669 | // Return the error code from the function. |
| 17696 | const error_set_type = try mod.singleErrorSetTypeNts(err_name); | 17670 | const error_set_type = try mod.singleErrorSetType(err_name); |
| 17697 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 17671 | const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 17698 | .ty = error_set_type.toIntern(), | 17672 | .ty = error_set_type.toIntern(), |
| 17699 | .name = err_name, | 17673 | .name = err_name, |
| ... | @@ -18003,7 +17977,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18003,7 +17977,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18003 | if (elem_ty.zigTypeTag(mod) == .NoReturn) | 17977 | if (elem_ty.zigTypeTag(mod) == .NoReturn) |
| 18004 | return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{}); | 17978 | return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{}); |
| 18005 | | 17979 | |
| 18006 | const target = sema.mod.getTarget(); | 17980 | const target = mod.getTarget(); |
| 18007 | | 17981 | |
| 18008 | var extra_i = extra.end; | 17982 | var extra_i = extra.end; |
| 18009 | | 17983 | |
| ... | @@ -18073,10 +18047,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18073,10 +18047,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18073 | } else if (inst_data.size == .C) { | 18047 | } else if (inst_data.size == .C) { |
| 18074 | if (!try sema.validateExternType(elem_ty, .other)) { | 18048 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 18075 | const msg = msg: { | 18049 | const msg = msg: { |
| 18076 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)}); | 18050 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 18077 | errdefer msg.destroy(sema.gpa); | 18051 | errdefer msg.destroy(sema.gpa); |
| 18078 | | 18052 | |
| 18079 | const src_decl = sema.mod.declPtr(block.src_decl); | 18053 | const src_decl = mod.declPtr(block.src_decl); |
| 18080 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other); | 18054 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other); |
| 18081 | | 18055 | |
| 18082 | try sema.addDeclaredHereNote(msg, elem_ty); | 18056 | try sema.addDeclaredHereNote(msg, elem_ty); |
| ... | @@ -18273,7 +18247,7 @@ fn zirStructInit( | ... | @@ -18273,7 +18247,7 @@ fn zirStructInit( |
| 18273 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); | 18247 | return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known"); |
| 18274 | }; | 18248 | }; |
| 18275 | | 18249 | |
| 18276 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), sema.mod)) { | 18250 | if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) { |
| 18277 | return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index); | 18251 | return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index); |
| 18278 | } | 18252 | } |
| 18279 | }; | 18253 | }; |
| ... | @@ -18307,8 +18281,8 @@ fn zirStructInit( | ... | @@ -18307,8 +18281,8 @@ fn zirStructInit( |
| 18307 | } | 18281 | } |
| 18308 | | 18282 | |
| 18309 | if (is_ref) { | 18283 | if (is_ref) { |
| 18310 | const target = sema.mod.getTarget(); | 18284 | const target = mod.getTarget(); |
| 18311 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18285 | const alloc_ty = try Type.ptr(sema.arena, mod, .{ |
| 18312 | .pointee_type = resolved_ty, | 18286 | .pointee_type = resolved_ty, |
| 18313 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18287 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18314 | }); | 18288 | }); |
| ... | @@ -18359,8 +18333,8 @@ fn finishStructInit( | ... | @@ -18359,8 +18333,8 @@ fn finishStructInit( |
| 18359 | } | 18333 | } |
| 18360 | } else { | 18334 | } else { |
| 18361 | const field_name = anon_struct.names[i]; | 18335 | const field_name = anon_struct.names[i]; |
| 18362 | const template = "missing struct field: {s}"; | 18336 | const template = "missing struct field: {}"; |
| 18363 | const args = .{ip.stringToSlice(field_name)}; | 18337 | const args = .{field_name.fmt(ip)}; |
| 18364 | if (root_msg) |msg| { | 18338 | if (root_msg) |msg| { |
| 18365 | try sema.errNote(block, init_src, msg, template, args); | 18339 | try sema.errNote(block, init_src, msg, template, args); |
| 18366 | } else { | 18340 | } else { |
| ... | @@ -18379,8 +18353,8 @@ fn finishStructInit( | ... | @@ -18379,8 +18353,8 @@ fn finishStructInit( |
| 18379 | | 18353 | |
| 18380 | if (field.default_val == .none) { | 18354 | if (field.default_val == .none) { |
| 18381 | const field_name = struct_obj.fields.keys()[i]; | 18355 | const field_name = struct_obj.fields.keys()[i]; |
| 18382 | const template = "missing struct field: {s}"; | 18356 | const template = "missing struct field: {}"; |
| 18383 | const args = .{ip.stringToSlice(field_name)}; | 18357 | const args = .{field_name.fmt(ip)}; |
| 18384 | if (root_msg) |msg| { | 18358 | if (root_msg) |msg| { |
| 18385 | try sema.errNote(block, init_src, msg, template, args); | 18359 | try sema.errNote(block, init_src, msg, template, args); |
| 18386 | } else { | 18360 | } else { |
| ... | @@ -18396,12 +18370,12 @@ fn finishStructInit( | ... | @@ -18396,12 +18370,12 @@ fn finishStructInit( |
| 18396 | | 18370 | |
| 18397 | if (root_msg) |msg| { | 18371 | if (root_msg) |msg| { |
| 18398 | if (mod.typeToStruct(struct_ty)) |struct_obj| { | 18372 | if (mod.typeToStruct(struct_ty)) |struct_obj| { |
| 18399 | const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod)); | 18373 | const fqn = try struct_obj.getFullyQualifiedName(mod); |
| 18400 | try mod.errNoteNonLazy( | 18374 | try mod.errNoteNonLazy( |
| 18401 | struct_obj.srcLoc(mod), | 18375 | struct_obj.srcLoc(mod), |
| 18402 | msg, | 18376 | msg, |
| 18403 | "struct '{s}' declared here", | 18377 | "struct '{}' declared here", |
| 18404 | .{fqn}, | 18378 | .{fqn.fmt(ip)}, |
| 18405 | ); | 18379 | ); |
| 18406 | } | 18380 | } |
| 18407 | root_msg = null; | 18381 | root_msg = null; |
| ... | @@ -18431,7 +18405,7 @@ fn finishStructInit( | ... | @@ -18431,7 +18405,7 @@ fn finishStructInit( |
| 18431 | if (is_ref) { | 18405 | if (is_ref) { |
| 18432 | try sema.resolveStructLayout(struct_ty); | 18406 | try sema.resolveStructLayout(struct_ty); |
| 18433 | const target = sema.mod.getTarget(); | 18407 | const target = sema.mod.getTarget(); |
| 18434 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18408 | const alloc_ty = try Type.ptr(sema.arena, mod, .{ |
| 18435 | .pointee_type = struct_ty, | 18409 | .pointee_type = struct_ty, |
| 18436 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18410 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18437 | }); | 18411 | }); |
| ... | @@ -18489,7 +18463,7 @@ fn zirStructInitAnon( | ... | @@ -18489,7 +18463,7 @@ fn zirStructInitAnon( |
| 18489 | const gop = fields.getOrPutAssumeCapacity(name_ip); | 18463 | const gop = fields.getOrPutAssumeCapacity(name_ip); |
| 18490 | if (gop.found_existing) { | 18464 | if (gop.found_existing) { |
| 18491 | const msg = msg: { | 18465 | const msg = msg: { |
| 18492 | const decl = sema.mod.declPtr(block.src_decl); | 18466 | const decl = mod.declPtr(block.src_decl); |
| 18493 | const field_src = mod.initSrc(src.node_offset.x, decl, i); | 18467 | const field_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18494 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); | 18468 | const msg = try sema.errMsg(block, field_src, "duplicate field", .{}); |
| 18495 | errdefer msg.destroy(gpa); | 18469 | errdefer msg.destroy(gpa); |
| ... | @@ -18506,7 +18480,7 @@ fn zirStructInitAnon( | ... | @@ -18506,7 +18480,7 @@ fn zirStructInitAnon( |
| 18506 | field_ty.* = sema.typeOf(init).toIntern(); | 18480 | field_ty.* = sema.typeOf(init).toIntern(); |
| 18507 | if (field_ty.toType().zigTypeTag(mod) == .Opaque) { | 18481 | if (field_ty.toType().zigTypeTag(mod) == .Opaque) { |
| 18508 | const msg = msg: { | 18482 | const msg = msg: { |
| 18509 | const decl = sema.mod.declPtr(block.src_decl); | 18483 | const decl = mod.declPtr(block.src_decl); |
| 18510 | const field_src = mod.initSrc(src.node_offset.x, decl, i); | 18484 | const field_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18511 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 18485 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 18512 | errdefer msg.destroy(sema.gpa); | 18486 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -18542,7 +18516,7 @@ fn zirStructInitAnon( | ... | @@ -18542,7 +18516,7 @@ fn zirStructInitAnon( |
| 18542 | | 18516 | |
| 18543 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 18517 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 18544 | error.NeededSourceLocation => { | 18518 | error.NeededSourceLocation => { |
| 18545 | const decl = sema.mod.declPtr(block.src_decl); | 18519 | const decl = mod.declPtr(block.src_decl); |
| 18546 | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 18520 | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 18547 | try sema.requireRuntimeBlock(block, src, field_src); | 18521 | try sema.requireRuntimeBlock(block, src, field_src); |
| 18548 | unreachable; | 18522 | unreachable; |
| ... | @@ -18551,8 +18525,8 @@ fn zirStructInitAnon( | ... | @@ -18551,8 +18525,8 @@ fn zirStructInitAnon( |
| 18551 | }; | 18525 | }; |
| 18552 | | 18526 | |
| 18553 | if (is_ref) { | 18527 | if (is_ref) { |
| 18554 | const target = sema.mod.getTarget(); | 18528 | const target = mod.getTarget(); |
| 18555 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18529 | const alloc_ty = try Type.ptr(sema.arena, mod, .{ |
| 18556 | .pointee_type = tuple_ty.toType(), | 18530 | .pointee_type = tuple_ty.toType(), |
| 18557 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18531 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18558 | }); | 18532 | }); |
| ... | @@ -18563,7 +18537,7 @@ fn zirStructInitAnon( | ... | @@ -18563,7 +18537,7 @@ fn zirStructInitAnon( |
| 18563 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); | 18537 | const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index); |
| 18564 | extra_index = item.end; | 18538 | extra_index = item.end; |
| 18565 | | 18539 | |
| 18566 | const field_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18540 | const field_ptr_ty = try Type.ptr(sema.arena, mod, .{ |
| 18567 | .mutable = true, | 18541 | .mutable = true, |
| 18568 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18542 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18569 | .pointee_type = field_ty.toType(), | 18543 | .pointee_type = field_ty.toType(), |
| ... | @@ -18617,7 +18591,7 @@ fn zirArrayInit( | ... | @@ -18617,7 +18591,7 @@ fn zirArrayInit( |
| 18617 | array_ty.elemType2(mod); | 18591 | array_ty.elemType2(mod); |
| 18618 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | 18592 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { |
| 18619 | error.NeededSourceLocation => { | 18593 | error.NeededSourceLocation => { |
| 18620 | const decl = sema.mod.declPtr(block.src_decl); | 18594 | const decl = mod.declPtr(block.src_decl); |
| 18621 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | 18595 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); |
| 18622 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | 18596 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); |
| 18623 | unreachable; | 18597 | unreachable; |
| ... | @@ -18653,7 +18627,7 @@ fn zirArrayInit( | ... | @@ -18653,7 +18627,7 @@ fn zirArrayInit( |
| 18653 | | 18627 | |
| 18654 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 18628 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 18655 | error.NeededSourceLocation => { | 18629 | error.NeededSourceLocation => { |
| 18656 | const decl = sema.mod.declPtr(block.src_decl); | 18630 | const decl = mod.declPtr(block.src_decl); |
| 18657 | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 18631 | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 18658 | try sema.requireRuntimeBlock(block, src, elem_src); | 18632 | try sema.requireRuntimeBlock(block, src, elem_src); |
| 18659 | unreachable; | 18633 | unreachable; |
| ... | @@ -18663,8 +18637,8 @@ fn zirArrayInit( | ... | @@ -18663,8 +18637,8 @@ fn zirArrayInit( |
| 18663 | try sema.queueFullTypeResolution(array_ty); | 18637 | try sema.queueFullTypeResolution(array_ty); |
| 18664 | | 18638 | |
| 18665 | if (is_ref) { | 18639 | if (is_ref) { |
| 18666 | const target = sema.mod.getTarget(); | 18640 | const target = mod.getTarget(); |
| 18667 | const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18641 | const alloc_ty = try Type.ptr(sema.arena, mod, .{ |
| 18668 | .pointee_type = array_ty, | 18642 | .pointee_type = array_ty, |
| 18669 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18643 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18670 | }); | 18644 | }); |
| ... | @@ -18672,7 +18646,7 @@ fn zirArrayInit( | ... | @@ -18672,7 +18646,7 @@ fn zirArrayInit( |
| 18672 | | 18646 | |
| 18673 | if (array_ty.isTuple(mod)) { | 18647 | if (array_ty.isTuple(mod)) { |
| 18674 | for (resolved_args, 0..) |arg, i| { | 18648 | for (resolved_args, 0..) |arg, i| { |
| 18675 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18649 | const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{ |
| 18676 | .mutable = true, | 18650 | .mutable = true, |
| 18677 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18651 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18678 | .pointee_type = array_ty.structFieldType(i, mod), | 18652 | .pointee_type = array_ty.structFieldType(i, mod), |
| ... | @@ -18686,7 +18660,7 @@ fn zirArrayInit( | ... | @@ -18686,7 +18660,7 @@ fn zirArrayInit( |
| 18686 | return sema.makePtrConst(block, alloc); | 18660 | return sema.makePtrConst(block, alloc); |
| 18687 | } | 18661 | } |
| 18688 | | 18662 | |
| 18689 | const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{ | 18663 | const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{ |
| 18690 | .mutable = true, | 18664 | .mutable = true, |
| 18691 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), | 18665 | .@"addrspace" = target_util.defaultAddressSpace(target, .local), |
| 18692 | .pointee_type = array_ty.elemType2(mod), | 18666 | .pointee_type = array_ty.elemType2(mod), |
| ... | @@ -18959,8 +18933,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -18959,8 +18933,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18959 | | 18933 | |
| 18960 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { | 18934 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { |
| 18961 | const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name; | 18935 | const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 18962 | const bytes = sema.mod.intern_pool.stringToSlice(err_name); | 18936 | return sema.addStrLit(block, sema.mod.intern_pool.stringToSlice(err_name)); |
| 18963 | return sema.addStrLit(block, bytes); | | |
| 18964 | } | 18937 | } |
| 18965 | | 18938 | |
| 18966 | // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass | 18939 | // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass |
| ... | @@ -19051,8 +19024,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19051,8 +19024,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19051 | .EnumLiteral => { | 19024 | .EnumLiteral => { |
| 19052 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); | 19025 | const val = try sema.resolveConstValue(block, .unneeded, operand, ""); |
| 19053 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; | 19026 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 19054 | const bytes = ip.stringToSlice(tag_name); | 19027 | return sema.addStrLit(block, ip.stringToSlice(tag_name)); |
| 19055 | return sema.addStrLit(block, bytes); | | |
| 19056 | }, | 19028 | }, |
| 19057 | .Enum => operand_ty, | 19029 | .Enum => operand_ty, |
| 19058 | .Union => operand_ty.unionTagType(mod) orelse { | 19030 | .Union => operand_ty.unionTagType(mod) orelse { |
| ... | @@ -19083,8 +19055,8 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19083,8 +19055,8 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19083 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { | 19055 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| 19084 | const enum_decl = mod.declPtr(enum_decl_index); | 19056 | const enum_decl = mod.declPtr(enum_decl_index); |
| 19085 | const msg = msg: { | 19057 | const msg = msg: { |
| 19086 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{s}'", .{ | 19058 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{ |
| 19087 | val.fmtValue(enum_ty, sema.mod), ip.stringToSlice(enum_decl.name), | 19059 | val.fmtValue(enum_ty, sema.mod), enum_decl.name.fmt(ip), |
| 19088 | }); | 19060 | }); |
| 19089 | errdefer msg.destroy(sema.gpa); | 19061 | errdefer msg.destroy(sema.gpa); |
| 19090 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); | 19062 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); |
| ... | @@ -19374,8 +19346,8 @@ fn zirReify( | ... | @@ -19374,8 +19346,8 @@ fn zirReify( |
| 19374 | _ = try mod.getErrorValue(name); | 19346 | _ = try mod.getErrorValue(name); |
| 19375 | const gop = names.getOrPutAssumeCapacity(name); | 19347 | const gop = names.getOrPutAssumeCapacity(name); |
| 19376 | if (gop.found_existing) { | 19348 | if (gop.found_existing) { |
| 19377 | return sema.fail(block, src, "duplicate error '{s}'", .{ | 19349 | return sema.fail(block, src, "duplicate error '{}'", .{ |
| 19378 | ip.stringToSlice(name), | 19350 | name.fmt(ip), |
| 19379 | }); | 19351 | }); |
| 19380 | } | 19352 | } |
| 19381 | } | 19353 | } |
| ... | @@ -19487,8 +19459,8 @@ fn zirReify( | ... | @@ -19487,8 +19459,8 @@ fn zirReify( |
| 19487 | | 19459 | |
| 19488 | if (!try sema.intFitsInType(value_val, int_tag_ty, null)) { | 19460 | if (!try sema.intFitsInType(value_val, int_tag_ty, null)) { |
| 19489 | // TODO: better source location | 19461 | // TODO: better source location |
| 19490 | return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{ | 19462 | return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{ |
| 19491 | ip.stringToSlice(field_name), | 19463 | field_name.fmt(ip), |
| 19492 | value_val.fmtValue(Type.comptime_int, mod), | 19464 | value_val.fmtValue(Type.comptime_int, mod), |
| 19493 | int_tag_ty.fmt(mod), | 19465 | int_tag_ty.fmt(mod), |
| 19494 | }); | 19466 | }); |
| ... | @@ -19496,8 +19468,8 @@ fn zirReify( | ... | @@ -19496,8 +19468,8 @@ fn zirReify( |
| 19496 | | 19468 | |
| 19497 | if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| { | 19469 | if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| { |
| 19498 | const msg = msg: { | 19470 | const msg = msg: { |
| 19499 | const msg = try sema.errMsg(block, src, "duplicate enum field '{s}'", .{ | 19471 | const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{ |
| 19500 | ip.stringToSlice(field_name), | 19472 | field_name.fmt(ip), |
| 19501 | }); | 19473 | }); |
| 19502 | errdefer msg.destroy(gpa); | 19474 | errdefer msg.destroy(gpa); |
| 19503 | _ = other_index; // TODO: this note is incorrect | 19475 | _ = other_index; // TODO: this note is incorrect |
| ... | @@ -19690,7 +19662,10 @@ fn zirReify( | ... | @@ -19690,7 +19662,10 @@ fn zirReify( |
| 19690 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; | 19662 | const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type; |
| 19691 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { | 19663 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 19692 | const msg = msg: { | 19664 | const msg = msg: { |
| 19693 | const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod) }); | 19665 | const msg = try sema.errMsg(block, src, "no field named '{}' in enum '{}'", .{ |
| | 19666 | field_name.fmt(ip), |
| | 19667 | union_obj.tag_ty.fmt(mod), |
| | 19668 | }); |
| 19694 | errdefer msg.destroy(gpa); | 19669 | errdefer msg.destroy(gpa); |
| 19695 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 19670 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| 19696 | break :msg msg; | 19671 | break :msg msg; |
| ... | @@ -19706,7 +19681,7 @@ fn zirReify( | ... | @@ -19706,7 +19681,7 @@ fn zirReify( |
| 19706 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); | 19681 | const gop = union_obj.fields.getOrPutAssumeCapacity(field_name); |
| 19707 | if (gop.found_existing) { | 19682 | if (gop.found_existing) { |
| 19708 | // TODO: better source location | 19683 | // TODO: better source location |
| 19709 | return sema.fail(block, src, "duplicate union field {s}", .{ip.stringToSlice(field_name)}); | 19684 | return sema.fail(block, src, "duplicate union field {}", .{field_name.fmt(ip)}); |
| 19710 | } | 19685 | } |
| 19711 | | 19686 | |
| 19712 | const field_ty = type_val.toType(); | 19687 | const field_ty = type_val.toType(); |
| ... | @@ -19762,8 +19737,8 @@ fn zirReify( | ... | @@ -19762,8 +19737,8 @@ fn zirReify( |
| 19762 | const enum_ty = union_obj.tag_ty; | 19737 | const enum_ty = union_obj.tag_ty; |
| 19763 | for (tag_info.names, 0..) |field_name, field_index| { | 19738 | for (tag_info.names, 0..) |field_name, field_index| { |
| 19764 | if (explicit_tags_seen[field_index]) continue; | 19739 | if (explicit_tags_seen[field_index]) continue; |
| 19765 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ | 19740 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{ |
| 19766 | ip.stringToSlice(field_name), | 19741 | field_name.fmt(ip), |
| 19767 | }); | 19742 | }); |
| 19768 | } | 19743 | } |
| 19769 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 19744 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -19981,14 +19956,12 @@ fn reifyStruct( | ... | @@ -19981,14 +19956,12 @@ fn reifyStruct( |
| 19981 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); | 19956 | const field_name = try name_val.toIpString(Type.slice_const_u8, mod); |
| 19982 | | 19957 | |
| 19983 | if (is_tuple) { | 19958 | if (is_tuple) { |
| 19984 | const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch { | 19959 | const field_index = field_name.toUnsigned(ip) orelse return sema.fail( |
| 19985 | return sema.fail( | 19960 | block, |
| 19986 | block, | 19961 | src, |
| 19987 | src, | 19962 | "tuple cannot have non-numeric field '{}'", |
| 19988 | "tuple cannot have non-numeric field '{s}'", | 19963 | .{field_name.fmt(ip)}, |
| 19989 | .{ip.stringToSlice(field_name)}, | 19964 | ); |
| 19990 | ); | | |
| 19991 | }; | | |
| 19992 | | 19965 | |
| 19993 | if (field_index >= fields_len) { | 19966 | if (field_index >= fields_len) { |
| 19994 | return sema.fail( | 19967 | return sema.fail( |
| ... | @@ -20002,7 +19975,7 @@ fn reifyStruct( | ... | @@ -20002,7 +19975,7 @@ fn reifyStruct( |
| 20002 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); | 19975 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 20003 | if (gop.found_existing) { | 19976 | if (gop.found_existing) { |
| 20004 | // TODO: better source location | 19977 | // TODO: better source location |
| 20005 | return sema.fail(block, src, "duplicate struct field {s}", .{ip.stringToSlice(field_name)}); | 19978 | return sema.fail(block, src, "duplicate struct field {}", .{field_name.fmt(ip)}); |
| 20006 | } | 19979 | } |
| 20007 | | 19980 | |
| 20008 | const field_ty = type_val.toType(); | 19981 | const field_ty = type_val.toType(); |
| ... | @@ -20443,14 +20416,14 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -20443,14 +20416,14 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 20443 | | 20416 | |
| 20444 | if (maybe_operand_val) |val| { | 20417 | if (maybe_operand_val) |val| { |
| 20445 | if (!dest_ty.isAnyError(mod)) { | 20418 | if (!dest_ty.isAnyError(mod)) { |
| 20446 | const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.toIntern()).err.name); | 20419 | const error_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 20447 | if (!dest_ty.errorSetHasField(error_name, mod)) { | 20420 | if (!Type.errorSetHasFieldIp(ip, dest_ty.toIntern(), error_name)) { |
| 20448 | const msg = msg: { | 20421 | const msg = msg: { |
| 20449 | const msg = try sema.errMsg( | 20422 | const msg = try sema.errMsg( |
| 20450 | block, | 20423 | block, |
| 20451 | src, | 20424 | src, |
| 20452 | "'error.{s}' not a member of error set '{}'", | 20425 | "'error.{}' not a member of error set '{}'", |
| 20453 | .{ error_name, dest_ty.fmt(sema.mod) }, | 20426 | .{ error_name.fmt(ip), dest_ty.fmt(sema.mod) }, |
| 20454 | ); | 20427 | ); |
| 20455 | errdefer msg.destroy(sema.gpa); | 20428 | errdefer msg.destroy(sema.gpa); |
| 20456 | try sema.addDeclaredHereNote(msg, dest_ty); | 20429 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | @@ -21448,7 +21421,7 @@ fn resolveExportOptions( | ... | @@ -21448,7 +21421,7 @@ fn resolveExportOptions( |
| 21448 | block: *Block, | 21421 | block: *Block, |
| 21449 | src: LazySrcLoc, | 21422 | src: LazySrcLoc, |
| 21450 | zir_ref: Zir.Inst.Ref, | 21423 | zir_ref: Zir.Inst.Ref, |
| 21451 | ) CompileError!std.builtin.ExportOptions { | 21424 | ) CompileError!Module.Export.Options { |
| 21452 | const mod = sema.mod; | 21425 | const mod = sema.mod; |
| 21453 | const gpa = sema.gpa; | 21426 | const gpa = sema.gpa; |
| 21454 | const ip = &mod.intern_pool; | 21427 | const ip = &mod.intern_pool; |
| ... | @@ -21492,10 +21465,10 @@ fn resolveExportOptions( | ... | @@ -21492,10 +21465,10 @@ fn resolveExportOptions( |
| 21492 | }); | 21465 | }); |
| 21493 | } | 21466 | } |
| 21494 | | 21467 | |
| 21495 | return std.builtin.ExportOptions{ | 21468 | return .{ |
| 21496 | .name = name, | 21469 | .name = try ip.getOrPutString(gpa, name), |
| 21497 | .linkage = linkage, | 21470 | .linkage = linkage, |
| 21498 | .section = section, | 21471 | .section = try ip.getOrPutStringOpt(gpa, section), |
| 21499 | .visibility = visibility, | 21472 | .visibility = visibility, |
| 21500 | }; | 21473 | }; |
| 21501 | } | 21474 | } |
| ... | @@ -22391,9 +22364,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -22391,9 +22364,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 22391 | const msg = try sema.errMsg( | 22364 | const msg = try sema.errMsg( |
| 22392 | block, | 22365 | block, |
| 22393 | src, | 22366 | src, |
| 22394 | "field '{s}' has index '{d}' but pointer value is index '{d}' of struct '{}'", | 22367 | "field '{}' has index '{d}' but pointer value is index '{d}' of struct '{}'", |
| 22395 | .{ | 22368 | .{ |
| 22396 | ip.stringToSlice(field_name), | 22369 | field_name.fmt(ip), |
| 22397 | field_index, | 22370 | field_index, |
| 22398 | field.index, | 22371 | field.index, |
| 22399 | parent_ty.fmt(sema.mod), | 22372 | parent_ty.fmt(sema.mod), |
| ... | @@ -23440,7 +23413,12 @@ fn resolveExternOptions( | ... | @@ -23440,7 +23413,12 @@ fn resolveExternOptions( |
| 23440 | block: *Block, | 23413 | block: *Block, |
| 23441 | src: LazySrcLoc, | 23414 | src: LazySrcLoc, |
| 23442 | zir_ref: Zir.Inst.Ref, | 23415 | zir_ref: Zir.Inst.Ref, |
| 23443 | ) CompileError!std.builtin.ExternOptions { | 23416 | ) CompileError!struct { |
| | 23417 | name: InternPool.NullTerminatedString, |
| | 23418 | library_name: InternPool.OptionalNullTerminatedString = .none, |
| | 23419 | linkage: std.builtin.GlobalLinkage = .Strong, |
| | 23420 | is_thread_local: bool = false, |
| | 23421 | } { |
| 23444 | const mod = sema.mod; | 23422 | const mod = sema.mod; |
| 23445 | const gpa = sema.gpa; | 23423 | const gpa = sema.gpa; |
| 23446 | const ip = &mod.intern_pool; | 23424 | const ip = &mod.intern_pool; |
| ... | @@ -23483,9 +23461,9 @@ fn resolveExternOptions( | ... | @@ -23483,9 +23461,9 @@ fn resolveExternOptions( |
| 23483 | return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{}); | 23461 | return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{}); |
| 23484 | } | 23462 | } |
| 23485 | | 23463 | |
| 23486 | return std.builtin.ExternOptions{ | 23464 | return .{ |
| 23487 | .name = name, | 23465 | .name = try ip.getOrPutString(gpa, name), |
| 23488 | .library_name = library_name, | 23466 | .library_name = try ip.getOrPutStringOpt(gpa, library_name), |
| 23489 | .linkage = linkage, | 23467 | .linkage = linkage, |
| 23490 | .is_thread_local = is_thread_local_val.toBool(), | 23468 | .is_thread_local = is_thread_local_val.toBool(), |
| 23491 | }; | 23469 | }; |
| ... | @@ -23533,7 +23511,7 @@ fn zirBuiltinExtern( | ... | @@ -23533,7 +23511,7 @@ fn zirBuiltinExtern( |
| 23533 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); | 23511 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null); |
| 23534 | errdefer mod.destroyDecl(new_decl_index); | 23512 | errdefer mod.destroyDecl(new_decl_index); |
| 23535 | const new_decl = mod.declPtr(new_decl_index); | 23513 | const new_decl = mod.declPtr(new_decl_index); |
| 23536 | new_decl.name = try mod.intern_pool.getOrPutString(sema.gpa, options.name); | 23514 | new_decl.name = options.name; |
| 23537 | | 23515 | |
| 23538 | { | 23516 | { |
| 23539 | const new_var = try mod.intern(.{ .variable = .{ | 23517 | const new_var = try mod.intern(.{ .variable = .{ |
| ... | @@ -24459,8 +24437,8 @@ fn fieldVal( | ... | @@ -24459,8 +24437,8 @@ fn fieldVal( |
| 24459 | return sema.fail( | 24437 | return sema.fail( |
| 24460 | block, | 24438 | block, |
| 24461 | field_name_src, | 24439 | field_name_src, |
| 24462 | "no member named '{s}' in '{}'", | 24440 | "no member named '{}' in '{}'", |
| 24463 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, | 24441 | .{ field_name.fmt(ip), object_ty.fmt(mod) }, |
| 24464 | ); | 24442 | ); |
| 24465 | } | 24443 | } |
| 24466 | }, | 24444 | }, |
| ... | @@ -24483,8 +24461,8 @@ fn fieldVal( | ... | @@ -24483,8 +24461,8 @@ fn fieldVal( |
| 24483 | return sema.fail( | 24461 | return sema.fail( |
| 24484 | block, | 24462 | block, |
| 24485 | field_name_src, | 24463 | field_name_src, |
| 24486 | "no member named '{s}' in '{}'", | 24464 | "no member named '{}' in '{}'", |
| 24487 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, | 24465 | .{ field_name.fmt(ip), object_ty.fmt(mod) }, |
| 24488 | ); | 24466 | ); |
| 24489 | } | 24467 | } |
| 24490 | } | 24468 | } |
| ... | @@ -24504,8 +24482,8 @@ fn fieldVal( | ... | @@ -24504,8 +24482,8 @@ fn fieldVal( |
| 24504 | .error_set_type => |error_set_type| blk: { | 24482 | .error_set_type => |error_set_type| blk: { |
| 24505 | if (error_set_type.nameIndex(ip, field_name) != null) break :blk; | 24483 | if (error_set_type.nameIndex(ip, field_name) != null) break :blk; |
| 24506 | const msg = msg: { | 24484 | const msg = msg: { |
| 24507 | const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{ | 24485 | const msg = try sema.errMsg(block, src, "no error named '{}' in '{}'", .{ |
| 24508 | ip.stringToSlice(field_name), child_type.fmt(mod), | 24486 | field_name.fmt(ip), child_type.fmt(mod), |
| 24509 | }); | 24487 | }); |
| 24510 | errdefer msg.destroy(sema.gpa); | 24488 | errdefer msg.destroy(sema.gpa); |
| 24511 | try sema.addDeclaredHereNote(msg, child_type); | 24489 | try sema.addDeclaredHereNote(msg, child_type); |
| ... | @@ -24526,7 +24504,7 @@ fn fieldVal( | ... | @@ -24526,7 +24504,7 @@ fn fieldVal( |
| 24526 | const error_set_type = if (!child_type.isAnyError(mod)) | 24504 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24527 | child_type | 24505 | child_type |
| 24528 | else | 24506 | else |
| 24529 | try mod.singleErrorSetTypeNts(field_name); | 24507 | try mod.singleErrorSetType(field_name); |
| 24530 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ | 24508 | return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{ |
| 24531 | .ty = error_set_type.toIntern(), | 24509 | .ty = error_set_type.toIntern(), |
| 24532 | .name = field_name, | 24510 | .name = field_name, |
| ... | @@ -24646,8 +24624,8 @@ fn fieldPtr( | ... | @@ -24646,8 +24624,8 @@ fn fieldPtr( |
| 24646 | return sema.fail( | 24624 | return sema.fail( |
| 24647 | block, | 24625 | block, |
| 24648 | field_name_src, | 24626 | field_name_src, |
| 24649 | "no member named '{s}' in '{}'", | 24627 | "no member named '{}' in '{}'", |
| 24650 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, | 24628 | .{ field_name.fmt(ip), object_ty.fmt(mod) }, |
| 24651 | ); | 24629 | ); |
| 24652 | } | 24630 | } |
| 24653 | }, | 24631 | }, |
| ... | @@ -24705,8 +24683,8 @@ fn fieldPtr( | ... | @@ -24705,8 +24683,8 @@ fn fieldPtr( |
| 24705 | return sema.fail( | 24683 | return sema.fail( |
| 24706 | block, | 24684 | block, |
| 24707 | field_name_src, | 24685 | field_name_src, |
| 24708 | "no member named '{s}' in '{}'", | 24686 | "no member named '{}' in '{}'", |
| 24709 | .{ ip.stringToSlice(field_name), object_ty.fmt(mod) }, | 24687 | .{ field_name.fmt(ip), object_ty.fmt(mod) }, |
| 24710 | ); | 24688 | ); |
| 24711 | } | 24689 | } |
| 24712 | }, | 24690 | }, |
| ... | @@ -24728,8 +24706,8 @@ fn fieldPtr( | ... | @@ -24728,8 +24706,8 @@ fn fieldPtr( |
| 24728 | if (error_set_type.nameIndex(ip, field_name) != null) { | 24706 | if (error_set_type.nameIndex(ip, field_name) != null) { |
| 24729 | break :blk; | 24707 | break :blk; |
| 24730 | } | 24708 | } |
| 24731 | return sema.fail(block, src, "no error named '{s}' in '{}'", .{ | 24709 | return sema.fail(block, src, "no error named '{}' in '{}'", .{ |
| 24732 | ip.stringToSlice(field_name), child_type.fmt(mod), | 24710 | field_name.fmt(ip), child_type.fmt(mod), |
| 24733 | }); | 24711 | }); |
| 24734 | }, | 24712 | }, |
| 24735 | .inferred_error_set_type => { | 24713 | .inferred_error_set_type => { |
| ... | @@ -24747,7 +24725,7 @@ fn fieldPtr( | ... | @@ -24747,7 +24725,7 @@ fn fieldPtr( |
| 24747 | const error_set_type = if (!child_type.isAnyError(mod)) | 24725 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 24748 | child_type | 24726 | child_type |
| 24749 | else | 24727 | else |
| 24750 | try mod.singleErrorSetTypeNts(field_name); | 24728 | try mod.singleErrorSetType(field_name); |
| 24751 | return sema.analyzeDeclRef(try anon_decl.finish( | 24729 | return sema.analyzeDeclRef(try anon_decl.finish( |
| 24752 | error_set_type, | 24730 | error_set_type, |
| 24753 | (try mod.intern(.{ .err = .{ | 24731 | (try mod.intern(.{ .err = .{ |
| ... | @@ -24880,10 +24858,10 @@ fn fieldCallBind( | ... | @@ -24880,10 +24858,10 @@ fn fieldCallBind( |
| 24880 | if (ip.stringEqlSlice(field_name, "len")) { | 24858 | if (ip.stringEqlSlice(field_name, "len")) { |
| 24881 | return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) }; | 24859 | return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) }; |
| 24882 | } | 24860 | } |
| 24883 | if (std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10)) |field_index| { | 24861 | if (field_name.toUnsigned(ip)) |field_index| { |
| 24884 | if (field_index >= struct_ty.structFieldCount(mod)) break :find_field; | 24862 | if (field_index >= struct_ty.structFieldCount(mod)) break :find_field; |
| 24885 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr); | 24863 | return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr); |
| 24886 | } else |_| {} | 24864 | } |
| 24887 | } else { | 24865 | } else { |
| 24888 | const max = struct_ty.structFieldCount(mod); | 24866 | const max = struct_ty.structFieldCount(mod); |
| 24889 | for (0..max) |i_usize| { | 24867 | for (0..max) |i_usize| { |
| ... | @@ -24982,12 +24960,15 @@ fn fieldCallBind( | ... | @@ -24982,12 +24960,15 @@ fn fieldCallBind( |
| 24982 | }; | 24960 | }; |
| 24983 | | 24961 | |
| 24984 | const msg = msg: { | 24962 | const msg = msg: { |
| 24985 | const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ ip.stringToSlice(field_name), concrete_ty.fmt(mod) }); | 24963 | const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{ |
| | 24964 | field_name.fmt(ip), |
| | 24965 | concrete_ty.fmt(mod), |
| | 24966 | }); |
| 24986 | errdefer msg.destroy(sema.gpa); | 24967 | errdefer msg.destroy(sema.gpa); |
| 24987 | try sema.addDeclaredHereNote(msg, concrete_ty); | 24968 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 24988 | if (found_decl) |decl_idx| { | 24969 | if (found_decl) |decl_idx| { |
| 24989 | const decl = mod.declPtr(decl_idx); | 24970 | const decl = mod.declPtr(decl_idx); |
| 24990 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{ip.stringToSlice(field_name)}); | 24971 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)}); |
| 24991 | } | 24972 | } |
| 24992 | break :msg msg; | 24973 | break :msg msg; |
| 24993 | }; | 24974 | }; |
| ... | @@ -25047,8 +25028,8 @@ fn namespaceLookup( | ... | @@ -25047,8 +25028,8 @@ fn namespaceLookup( |
| 25047 | const decl = mod.declPtr(decl_index); | 25028 | const decl = mod.declPtr(decl_index); |
| 25048 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { | 25029 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 25049 | const msg = msg: { | 25030 | const msg = msg: { |
| 25050 | const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{ | 25031 | const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{ |
| 25051 | mod.intern_pool.stringToSlice(decl_name), | 25032 | decl_name.fmt(&mod.intern_pool), |
| 25052 | }); | 25033 | }); |
| 25053 | errdefer msg.destroy(gpa); | 25034 | errdefer msg.destroy(gpa); |
| 25054 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); | 25035 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); |
| ... | @@ -25299,21 +25280,20 @@ fn tupleFieldIndex( | ... | @@ -25299,21 +25280,20 @@ fn tupleFieldIndex( |
| 25299 | sema: *Sema, | 25280 | sema: *Sema, |
| 25300 | block: *Block, | 25281 | block: *Block, |
| 25301 | tuple_ty: Type, | 25282 | tuple_ty: Type, |
| 25302 | field_name_ip: InternPool.NullTerminatedString, | 25283 | field_name: InternPool.NullTerminatedString, |
| 25303 | field_name_src: LazySrcLoc, | 25284 | field_name_src: LazySrcLoc, |
| 25304 | ) CompileError!u32 { | 25285 | ) CompileError!u32 { |
| 25305 | const mod = sema.mod; | 25286 | const mod = sema.mod; |
| 25306 | const field_name = mod.intern_pool.stringToSlice(field_name_ip); | 25287 | assert(!mod.intern_pool.stringEqlSlice(field_name, "len")); |
| 25307 | assert(!std.mem.eql(u8, field_name, "len")); | 25288 | if (field_name.toUnsigned(&mod.intern_pool)) |field_index| { |
| 25308 | if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| { | | |
| 25309 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; | 25289 | if (field_index < tuple_ty.structFieldCount(mod)) return field_index; |
| 25310 | return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{ | 25290 | return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{ |
| 25311 | field_name, tuple_ty.fmt(mod), | 25291 | field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod), |
| 25312 | }); | 25292 | }); |
| 25313 | } else |_| {} | 25293 | } |
| 25314 | | 25294 | |
| 25315 | return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{ | 25295 | return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{ |
| 25316 | field_name, tuple_ty.fmt(mod), | 25296 | field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod), |
| 25317 | }); | 25297 | }); |
| 25318 | } | 25298 | } |
| 25319 | | 25299 | |
| ... | @@ -25389,8 +25369,8 @@ fn unionFieldPtr( | ... | @@ -25389,8 +25369,8 @@ fn unionFieldPtr( |
| 25389 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 25369 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); |
| 25390 | errdefer msg.destroy(sema.gpa); | 25370 | errdefer msg.destroy(sema.gpa); |
| 25391 | | 25371 | |
| 25392 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ | 25372 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| 25393 | ip.stringToSlice(field_name), | 25373 | field_name.fmt(ip), |
| 25394 | }); | 25374 | }); |
| 25395 | try sema.addDeclaredHereNote(msg, union_ty); | 25375 | try sema.addDeclaredHereNote(msg, union_ty); |
| 25396 | break :msg msg; | 25376 | break :msg msg; |
| ... | @@ -25413,9 +25393,9 @@ fn unionFieldPtr( | ... | @@ -25413,9 +25393,9 @@ fn unionFieldPtr( |
| 25413 | const msg = msg: { | 25393 | const msg = msg: { |
| 25414 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; | 25394 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25415 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 25395 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25416 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ | 25396 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ |
| 25417 | ip.stringToSlice(field_name), | 25397 | field_name.fmt(ip), |
| 25418 | ip.stringToSlice(active_field_name), | 25398 | active_field_name.fmt(ip), |
| 25419 | }); | 25399 | }); |
| 25420 | errdefer msg.destroy(sema.gpa); | 25400 | errdefer msg.destroy(sema.gpa); |
| 25421 | try sema.addDeclaredHereNote(msg, union_ty); | 25401 | try sema.addDeclaredHereNote(msg, union_ty); |
| ... | @@ -25486,8 +25466,8 @@ fn unionFieldVal( | ... | @@ -25486,8 +25466,8 @@ fn unionFieldVal( |
| 25486 | const msg = msg: { | 25466 | const msg = msg: { |
| 25487 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; | 25467 | const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?; |
| 25488 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); | 25468 | const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod); |
| 25489 | const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{ | 25469 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ |
| 25490 | ip.stringToSlice(field_name), ip.stringToSlice(active_field_name), | 25470 | field_name.fmt(ip), active_field_name.fmt(ip), |
| 25491 | }); | 25471 | }); |
| 25492 | errdefer msg.destroy(sema.gpa); | 25472 | errdefer msg.destroy(sema.gpa); |
| 25493 | try sema.addDeclaredHereNote(msg, union_ty); | 25473 | try sema.addDeclaredHereNote(msg, union_ty); |
| ... | @@ -26595,8 +26575,8 @@ fn coerceExtra( | ... | @@ -26595,8 +26575,8 @@ fn coerceExtra( |
| 26595 | const msg = try sema.errMsg( | 26575 | const msg = try sema.errMsg( |
| 26596 | block, | 26576 | block, |
| 26597 | inst_src, | 26577 | inst_src, |
| 26598 | "no field named '{s}' in enum '{}'", | 26578 | "no field named '{}' in enum '{}'", |
| 26599 | .{ mod.intern_pool.stringToSlice(string), dest_ty.fmt(mod) }, | 26579 | .{ string.fmt(&mod.intern_pool), dest_ty.fmt(mod) }, |
| 26600 | ); | 26580 | ); |
| 26601 | errdefer msg.destroy(sema.gpa); | 26581 | errdefer msg.destroy(sema.gpa); |
| 26602 | try sema.addDeclaredHereNote(msg, dest_ty); | 26582 | try sema.addDeclaredHereNote(msg, dest_ty); |
| ... | @@ -27051,9 +27031,8 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -27051,9 +27031,8 @@ const InMemoryCoercionResult = union(enum) { |
| 27051 | break; | 27031 | break; |
| 27052 | }, | 27032 | }, |
| 27053 | .missing_error => |missing_errors| { | 27033 | .missing_error => |missing_errors| { |
| 27054 | for (missing_errors) |err_index| { | 27034 | for (missing_errors) |err| { |
| 27055 | const err = mod.intern_pool.stringToSlice(err_index); | 27035 | try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)}); |
| 27056 | try sema.errNote(block, src, msg, "'error.{s}' not a member of destination error set", .{err}); | | |
| 27057 | } | 27036 | } |
| 27058 | break; | 27037 | break; |
| 27059 | }, | 27038 | }, |
| ... | @@ -28016,7 +27995,12 @@ fn storePtrVal( | ... | @@ -28016,7 +27995,12 @@ fn storePtrVal( |
| 28016 | .bad_decl_ty, .bad_ptr_ty => { | 27995 | .bad_decl_ty, .bad_ptr_ty => { |
| 28017 | // TODO show the decl declaration site in a note and explain whether the decl | 27996 | // TODO show the decl declaration site in a note and explain whether the decl |
| 28018 | // or the pointer is the problematic type | 27997 | // or the pointer is the problematic type |
| 28019 | return sema.fail(block, src, "comptime mutation of a reinterpreted pointer requires type '{}' to have a well-defined memory layout", .{mut_kit.ty.fmt(mod)}); | 27998 | return sema.fail( |
| | 27999 | block, |
| | 28000 | src, |
| | 28001 | "comptime mutation of a reinterpreted pointer requires type '{}' to have a well-defined memory layout", |
| | 28002 | .{mut_kit.ty.fmt(mod)}, |
| | 28003 | ); |
| 28020 | }, | 28004 | }, |
| 28021 | } | 28005 | } |
| 28022 | } | 28006 | } |
| ... | @@ -28678,7 +28662,12 @@ fn beginComptimePtrLoad( | ... | @@ -28678,7 +28662,12 @@ fn beginComptimePtrLoad( |
| 28678 | .null_value => return sema.fail(block, src, "attempt to use null value", .{}), | 28662 | .null_value => return sema.fail(block, src, "attempt to use null value", .{}), |
| 28679 | else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) { | 28663 | else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) { |
| 28680 | .error_union => |error_union| switch (error_union.val) { | 28664 | .error_union => |error_union| switch (error_union.val) { |
| 28681 | .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}), | 28665 | .err_name => |err_name| return sema.fail( |
| | 28666 | block, |
| | 28667 | src, |
| | 28668 | "attempt to unwrap error: {}", |
| | 28669 | .{err_name.fmt(&mod.intern_pool)}, |
| | 28670 | ), |
| 28682 | .payload => |payload| payload, | 28671 | .payload => |payload| payload, |
| 28683 | }, | 28672 | }, |
| 28684 | .opt => |opt| switch (opt.val) { | 28673 | .opt => |opt| switch (opt.val) { |
| ... | @@ -29077,8 +29066,8 @@ fn coerceEnumToUnion( | ... | @@ -29077,8 +29066,8 @@ fn coerceEnumToUnion( |
| 29077 | errdefer msg.destroy(sema.gpa); | 29066 | errdefer msg.destroy(sema.gpa); |
| 29078 | | 29067 | |
| 29079 | const field_name = union_obj.fields.keys()[field_index]; | 29068 | const field_name = union_obj.fields.keys()[field_index]; |
| 29080 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ | 29069 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| 29081 | ip.stringToSlice(field_name), | 29070 | field_name.fmt(ip), |
| 29082 | }); | 29071 | }); |
| 29083 | try sema.addDeclaredHereNote(msg, union_ty); | 29072 | try sema.addDeclaredHereNote(msg, union_ty); |
| 29084 | break :msg msg; | 29073 | break :msg msg; |
| ... | @@ -29088,14 +29077,14 @@ fn coerceEnumToUnion( | ... | @@ -29088,14 +29077,14 @@ fn coerceEnumToUnion( |
| 29088 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { | 29077 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 29089 | const msg = msg: { | 29078 | const msg = msg: { |
| 29090 | const field_name = union_obj.fields.keys()[field_index]; | 29079 | const field_name = union_obj.fields.keys()[field_index]; |
| 29091 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{ | 29080 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{ |
| 29092 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), | 29081 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), |
| 29093 | field_ty.fmt(sema.mod), ip.stringToSlice(field_name), | 29082 | field_ty.fmt(sema.mod), field_name.fmt(ip), |
| 29094 | }); | 29083 | }); |
| 29095 | errdefer msg.destroy(sema.gpa); | 29084 | errdefer msg.destroy(sema.gpa); |
| 29096 | | 29085 | |
| 29097 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{ | 29086 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| 29098 | ip.stringToSlice(field_name), | 29087 | field_name.fmt(ip), |
| 29099 | }); | 29088 | }); |
| 29100 | try sema.addDeclaredHereNote(msg, union_ty); | 29089 | try sema.addDeclaredHereNote(msg, union_ty); |
| 29101 | break :msg msg; | 29090 | break :msg msg; |
| ... | @@ -29165,8 +29154,8 @@ fn coerceEnumToUnion( | ... | @@ -29165,8 +29154,8 @@ fn coerceEnumToUnion( |
| 29165 | const field_name = field.key_ptr.*; | 29154 | const field_name = field.key_ptr.*; |
| 29166 | const field_ty = field.value_ptr.ty; | 29155 | const field_ty = field.value_ptr.ty; |
| 29167 | if (!(try sema.typeHasRuntimeBits(field_ty))) continue; | 29156 | if (!(try sema.typeHasRuntimeBits(field_ty))) continue; |
| 29168 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' has type '{}'", .{ | 29157 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{ |
| 29169 | ip.stringToSlice(field_name), | 29158 | field_name.fmt(ip), |
| 29170 | field_ty.fmt(sema.mod), | 29159 | field_ty.fmt(sema.mod), |
| 29171 | }); | 29160 | }); |
| 29172 | } | 29161 | } |
| ... | @@ -29522,8 +29511,8 @@ fn coerceTupleToStruct( | ... | @@ -29522,8 +29511,8 @@ fn coerceTupleToStruct( |
| 29522 | const field = fields.values()[i]; | 29511 | const field = fields.values()[i]; |
| 29523 | const field_src = inst_src; // TODO better source location | 29512 | const field_src = inst_src; // TODO better source location |
| 29524 | if (field.default_val == .none) { | 29513 | if (field.default_val == .none) { |
| 29525 | const template = "missing struct field: {s}"; | 29514 | const template = "missing struct field: {}"; |
| 29526 | const args = .{ip.stringToSlice(field_name)}; | 29515 | const args = .{field_name.fmt(ip)}; |
| 29527 | if (root_msg) |msg| { | 29516 | if (root_msg) |msg| { |
| 29528 | try sema.errNote(block, field_src, msg, template, args); | 29517 | try sema.errNote(block, field_src, msg, template, args); |
| 29529 | } else { | 29518 | } else { |
| ... | @@ -29666,8 +29655,8 @@ fn coerceTupleToTuple( | ... | @@ -29666,8 +29655,8 @@ fn coerceTupleToTuple( |
| 29666 | } | 29655 | } |
| 29667 | continue; | 29656 | continue; |
| 29668 | } | 29657 | } |
| 29669 | const template = "missing struct field: {s}"; | 29658 | const template = "missing struct field: {}"; |
| 29670 | const args = .{ip.stringToSlice(tuple_ty.structFieldName(i, mod))}; | 29659 | const args = .{tuple_ty.structFieldName(i, mod).fmt(ip)}; |
| 29671 | if (root_msg) |msg| { | 29660 | if (root_msg) |msg| { |
| 29672 | try sema.errNote(block, field_src, msg, template, args); | 29661 | try sema.errNote(block, field_src, msg, template, args); |
| 29673 | } else { | 29662 | } else { |
| ... | @@ -30097,7 +30086,7 @@ fn analyzeIsNonErrComptimeOnly( | ... | @@ -30097,7 +30086,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 30097 | if (err_union.isUndef(mod)) { | 30086 | if (err_union.isUndef(mod)) { |
| 30098 | return sema.addConstUndef(Type.bool); | 30087 | return sema.addConstUndef(Type.bool); |
| 30099 | } | 30088 | } |
| 30100 | if (err_union.getError(mod) == null) { | 30089 | if (err_union.getErrorName(mod) == .none) { |
| 30101 | return Air.Inst.Ref.bool_true; | 30090 | return Air.Inst.Ref.bool_true; |
| 30102 | } else { | 30091 | } else { |
| 30103 | return Air.Inst.Ref.bool_false; | 30092 | return Air.Inst.Ref.bool_false; |
| ... | @@ -32824,15 +32813,16 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32824,15 +32813,16 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32824 | extra_index += 1; | 32813 | extra_index += 1; |
| 32825 | | 32814 | |
| 32826 | // This string needs to outlive the ZIR code. | 32815 | // This string needs to outlive the ZIR code. |
| 32827 | const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s| s else try std.fmt.allocPrint(sema.arena, "{d}", .{ | 32816 | const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s| |
| 32828 | field_i, | 32817 | s |
| 32829 | })); | 32818 | else |
| | 32819 | try std.fmt.allocPrint(sema.arena, "{d}", .{field_i})); |
| 32830 | | 32820 | |
| 32831 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); | 32821 | const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name); |
| 32832 | if (gop.found_existing) { | 32822 | if (gop.found_existing) { |
| 32833 | const msg = msg: { | 32823 | const msg = msg: { |
| 32834 | const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy; | 32824 | const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy; |
| 32835 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{ip.stringToSlice(field_name)}); | 32825 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{}'", .{field_name.fmt(ip)}); |
| 32836 | errdefer msg.destroy(gpa); | 32826 | errdefer msg.destroy(gpa); |
| 32837 | | 32827 | |
| 32838 | const prev_field_index = struct_obj.fields.getIndex(field_name).?; | 32828 | const prev_field_index = struct_obj.fields.getIndex(field_name).?; |
| ... | @@ -33297,8 +33287,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33297,8 +33287,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33297 | if (gop.found_existing) { | 33287 | if (gop.found_existing) { |
| 33298 | const msg = msg: { | 33288 | const msg = msg: { |
| 33299 | const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy; | 33289 | const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy; |
| 33300 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{ | 33290 | const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{}'", .{ |
| 33301 | ip.stringToSlice(field_name), | 33291 | field_name.fmt(ip), |
| 33302 | }); | 33292 | }); |
| 33303 | errdefer msg.destroy(gpa); | 33293 | errdefer msg.destroy(gpa); |
| 33304 | | 33294 | |
| ... | @@ -33319,8 +33309,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33319,8 +33309,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33319 | .index = field_i, | 33309 | .index = field_i, |
| 33320 | .range = .type, | 33310 | .range = .type, |
| 33321 | }).lazy; | 33311 | }).lazy; |
| 33322 | const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{s}' in enum '{}'", .{ | 33312 | const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{ |
| 33323 | ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod), | 33313 | field_name.fmt(ip), union_obj.tag_ty.fmt(mod), |
| 33324 | }); | 33314 | }); |
| 33325 | errdefer msg.destroy(sema.gpa); | 33315 | errdefer msg.destroy(sema.gpa); |
| 33326 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 33316 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -33412,8 +33402,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -33412,8 +33402,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 33412 | const enum_ty = union_obj.tag_ty; | 33402 | const enum_ty = union_obj.tag_ty; |
| 33413 | for (tag_info.names, 0..) |field_name, field_index| { | 33403 | for (tag_info.names, 0..) |field_name, field_index| { |
| 33414 | if (explicit_tags_seen[field_index]) continue; | 33404 | if (explicit_tags_seen[field_index]) continue; |
| 33415 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{ | 33405 | try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{ |
| 33416 | ip.stringToSlice(field_name), | 33406 | field_name.fmt(ip), |
| 33417 | }); | 33407 | }); |
| 33418 | } | 33408 | } |
| 33419 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); | 33409 | try sema.addDeclaredHereNote(msg, union_obj.tag_ty); |
| ... | @@ -33442,22 +33432,12 @@ fn generateUnionTagTypeNumbered( | ... | @@ -33442,22 +33432,12 @@ fn generateUnionTagTypeNumbered( |
| 33442 | ) !Type { | 33432 | ) !Type { |
| 33443 | const mod = sema.mod; | 33433 | const mod = sema.mod; |
| 33444 | const gpa = sema.gpa; | 33434 | const gpa = sema.gpa; |
| 33445 | const ip = &mod.intern_pool; | | |
| 33446 | | 33435 | |
| 33447 | const src_decl = mod.declPtr(block.src_decl); | 33436 | const src_decl = mod.declPtr(block.src_decl); |
| 33448 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); | 33437 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33449 | errdefer mod.destroyDecl(new_decl_index); | 33438 | errdefer mod.destroyDecl(new_decl_index); |
| 33450 | const name = name: { | 33439 | const fqn = try union_obj.getFullyQualifiedName(mod); |
| 33451 | const prefix = "@typeInfo("; | 33440 | const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)}); |
| 33452 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); | | |
| 33453 | const suffix = ").Union.tag_type.?"; | | |
| 33454 | const start = ip.string_bytes.items.len; | | |
| 33455 | try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len); | | |
| 33456 | ip.string_bytes.appendSliceAssumeCapacity(prefix); | | |
| 33457 | ip.string_bytes.appendSliceAssumeCapacity(fqn); | | |
| 33458 | ip.string_bytes.appendSliceAssumeCapacity(suffix); | | |
| 33459 | break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start); | | |
| 33460 | }; | | |
| 33461 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ | 33441 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33462 | .ty = Type.noreturn, | 33442 | .ty = Type.noreturn, |
| 33463 | .val = Value.@"unreachable", | 33443 | .val = Value.@"unreachable", |
| ... | @@ -33496,7 +33476,6 @@ fn generateUnionTagTypeSimple( | ... | @@ -33496,7 +33476,6 @@ fn generateUnionTagTypeSimple( |
| 33496 | ) !Type { | 33476 | ) !Type { |
| 33497 | const mod = sema.mod; | 33477 | const mod = sema.mod; |
| 33498 | const gpa = sema.gpa; | 33478 | const gpa = sema.gpa; |
| 33499 | const ip = &mod.intern_pool; | | |
| 33500 | | 33479 | |
| 33501 | const new_decl_index = new_decl_index: { | 33480 | const new_decl_index = new_decl_index: { |
| 33502 | const union_obj = maybe_union_obj orelse { | 33481 | const union_obj = maybe_union_obj orelse { |
| ... | @@ -33508,17 +33487,8 @@ fn generateUnionTagTypeSimple( | ... | @@ -33508,17 +33487,8 @@ fn generateUnionTagTypeSimple( |
| 33508 | const src_decl = mod.declPtr(block.src_decl); | 33487 | const src_decl = mod.declPtr(block.src_decl); |
| 33509 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); | 33488 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope); |
| 33510 | errdefer mod.destroyDecl(new_decl_index); | 33489 | errdefer mod.destroyDecl(new_decl_index); |
| 33511 | const name = name: { | 33490 | const fqn = try union_obj.getFullyQualifiedName(mod); |
| 33512 | const prefix = "@typeInfo("; | 33491 | const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)}); |
| 33513 | const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod)); | | |
| 33514 | const suffix = ").Union.tag_type.?"; | | |
| 33515 | const start = ip.string_bytes.items.len; | | |
| 33516 | try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len); | | |
| 33517 | ip.string_bytes.appendSliceAssumeCapacity(prefix); | | |
| 33518 | ip.string_bytes.appendSliceAssumeCapacity(fqn); | | |
| 33519 | ip.string_bytes.appendSliceAssumeCapacity(suffix); | | |
| 33520 | break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start); | | |
| 33521 | }; | | |
| 33522 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ | 33492 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{ |
| 33523 | .ty = Type.noreturn, | 33493 | .ty = Type.noreturn, |
| 33524 | .val = Value.@"unreachable", | 33494 | .val = Value.@"unreachable", |
| ... | @@ -34456,8 +34426,8 @@ fn anonStructFieldIndex( | ... | @@ -34456,8 +34426,8 @@ fn anonStructFieldIndex( |
| 34456 | }, | 34426 | }, |
| 34457 | else => unreachable, | 34427 | else => unreachable, |
| 34458 | } | 34428 | } |
| 34459 | return sema.fail(block, field_src, "no field named '{s}' in anonymous struct '{}'", .{ | 34429 | return sema.fail(block, field_src, "no field named '{}' in anonymous struct '{}'", .{ |
| 34460 | mod.intern_pool.stringToSlice(field_name), struct_ty.fmt(sema.mod), | 34430 | field_name.fmt(&mod.intern_pool), struct_ty.fmt(sema.mod), |
| 34461 | }); | 34431 | }); |
| 34462 | } | 34432 | } |
| 34463 | | 34433 | |