authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-13 15:23:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log722bd22508a7f1f5ab05685002d30e8d7fc2b2a2
treefab71e5564eb42147bd1863fa67ebd1404cd6c6e
parent684aee32209932166713462cc341fa469aad0728

Sema: fix not setting up adhoc inferred error set correctly

for comptime/inline calls.

1 files changed, 10 insertions(+), 12 deletions(-)

src/Sema.zig+10-12
...@@ -157,9 +157,9 @@ pub const InferredErrorSet = struct {...@@ -157,9 +157,9 @@ pub const InferredErrorSet = struct {
157 arena: Allocator,157 arena: Allocator,
158 ) !void {158 ) !void {
159 switch (err_set_ty.toIntern()) {159 switch (err_set_ty.toIntern()) {
160 .anyerror_type => {160 .anyerror_type => self.resolved = .anyerror_type,
161 self.resolved = .anyerror_type;161 .adhoc_inferred_error_set_type => {}, // Adding an inferred error set to itself.
162 },162
163 else => switch (ip.indexToKey(err_set_ty.toIntern())) {163 else => switch (ip.indexToKey(err_set_ty.toIntern())) {
164 .error_set_type => |error_set_type| {164 .error_set_type => |error_set_type| {
165 for (error_set_type.names.get(ip)) |name| {165 for (error_set_type.names.get(ip)) |name| {
...@@ -7055,12 +7055,11 @@ fn analyzeCall(...@@ -7055,12 +7055,11 @@ fn analyzeCall(
70557055
7056 if (module_fn.analysis(ip).inferred_error_set) {7056 if (module_fn.analysis(ip).inferred_error_set) {
7057 // Create a fresh inferred error set type for inline/comptime calls.7057 // Create a fresh inferred error set type for inline/comptime calls.
7058 const error_set_ty = try mod.intern(.{ .inferred_error_set_type = module_fn_index });
7059 const ies = try sema.arena.create(InferredErrorSet);7058 const ies = try sema.arena.create(InferredErrorSet);
7060 ies.* = .{ .func = module_fn_index };7059 ies.* = .{ .func = .none };
7061 sema.fn_ret_ty_ies = ies;7060 sema.fn_ret_ty_ies = ies;
7062 sema.fn_ret_ty = (try ip.get(gpa, .{ .error_union_type = .{7061 sema.fn_ret_ty = (try ip.get(gpa, .{ .error_union_type = .{
7063 .error_set_type = error_set_ty,7062 .error_set_type = .adhoc_inferred_error_set_type,
7064 .payload_type = bare_return_type.toIntern(),7063 .payload_type = bare_return_type.toIntern(),
7065 } })).toType();7064 } })).toType();
7066 }7065 }
...@@ -7081,6 +7080,7 @@ fn analyzeCall(...@@ -7081,6 +7080,7 @@ fn analyzeCall(
7081 }7080 }
7082 }7081 }
70837082
7083 new_fn_info.return_type = sema.fn_ret_ty.toIntern();
7084 const new_func_resolved_ty = try mod.funcType(new_fn_info);7084 const new_func_resolved_ty = try mod.funcType(new_fn_info);
7085 if (!is_comptime_call and !block.is_typeof) {7085 if (!is_comptime_call and !block.is_typeof) {
7086 try sema.emitDbgInline(block, parent_func_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin);7086 try sema.emitDbgInline(block, parent_func_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin);
...@@ -8841,7 +8841,8 @@ fn funcCommon(...@@ -8841,7 +8841,8 @@ fn funcCommon(
8841 if (inferred_error_set) {8841 if (inferred_error_set) {
8842 assert(!is_extern);8842 assert(!is_extern);
8843 assert(has_body);8843 assert(has_body);
8844 try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src);8844 if (!ret_poison)
8845 try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src);
8845 const func_index = try ip.getFuncDeclIes(gpa, .{8846 const func_index = try ip.getFuncDeclIes(gpa, .{
8846 .owner_decl = sema.owner_decl_index,8847 .owner_decl = sema.owner_decl_index,
88478848
...@@ -34051,11 +34052,8 @@ fn resolveInferredErrorSet(...@@ -34051,11 +34052,8 @@ fn resolveInferredErrorSet(
34051 // In order to ensure that all dependencies are properly added to the set,34052 // In order to ensure that all dependencies are properly added to the set,
34052 // we need to ensure the function body is analyzed of the inferred error34053 // we need to ensure the function body is analyzed of the inferred error
34053 // set. However, in the case of comptime/inline function calls with34054 // set. However, in the case of comptime/inline function calls with
34054 // inferred error sets, each call gets a new InferredErrorSet object, which34055 // inferred error sets, each call gets an adhoc InferredErrorSet object, which
34055 // contains the `InternPool.Index` of the callee. Not only is the function34056 // has no corresponding function body.
34056 // not relevant to the inferred error set in this case, it may be a generic
34057 // function which would cause an assertion failure if we called
34058 // `ensureFuncBodyAnalyzed` on it here.
34059 const ies_func_owner_decl = mod.declPtr(func.owner_decl);34057 const ies_func_owner_decl = mod.declPtr(func.owner_decl);
34060 const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?;34058 const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?;
34061 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,34059 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,